gpt4 book ai didi

maven - 如何使用 'mvn test' 运行 Cucumber 测试

转载 作者:行者123 更新时间:2023-11-28 20:48:25 30 4
gpt4 key购买 nike

请注意,我使用的是 Kotlin。
另请注意,我有一个多模块应用程序。

我通过运行 RunCukesTest.kt 类成功地从 IDE 运行 Cucumber 测试。

我的问题是,当我运行命令 mvn test 时,RunCukesTest.kt 似乎没有运行,而且没有 .feature 经过测试。

我不确定是否需要配置 maven-surefire-plugin 才能使其正常工作。

domain-pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>smart-notes</artifactId>
<groupId>xxx</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>domain</artifactId>

<properties>
<cucumber.version>4.4.0</cucumber.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<junit.version>4.12</junit.version>
</properties>

<dependencies>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java8</artifactId>
<version>${cucumber.version}</version>
</dependency>

<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>${cucumber.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

parent-pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<packaging>pom</packaging>
<modules>
<module>domain</module>
<module>infra</module>
</modules>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>xxx</groupId>
<artifactId>smart-notes</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>smart-notes</name>
<description>Take quick smart notes</description>

<properties>
<java.version>1.8</java.version>
<kotlin.version>1.3.40</kotlin.version>
<junit-jupiter.version>5.4.2</junit-jupiter.version>
</properties>

<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-kotlin</artifactId>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-reflect</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
<version>${kotlin.version}</version>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>

<configuration>
<jvmTarget>1.8</jvmTarget>
<args>
<arg>-Xjsr305=strict</arg>
</args>
<compilerPlugins>
<plugin>spring</plugin>
</compilerPlugins>
</configuration>

<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-allopen</artifactId>
<version>${kotlin.version}</version>
</dependency>
</dependencies>
</plugin>

<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
</project>

RunCukesTest.kt

import cucumber.api.CucumberOptions
import cucumber.api.junit.Cucumber
import org.junit.runner.RunWith

@RunWith(Cucumber::class)
@CucumberOptions(
plugin = ["pretty"],
features = ["classpath:features"],
glue = ["classpath:acceptance.stepdefs"])
class RunCukesTest

some-feature.feature

Feature: Is it friday yet

Scenario: my scenario
Given today is Sunday
When I ask whether it's Friday yet
Then I should be told "Nope"

Maven 构建日志

[INFO] 
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ domain ---
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 9.209 s
[INFO] Finished at: 2019-06-23T16:46:35+02:00
[INFO] ------------------------------------------------------------------------

架构

  • 来源

    • 测试

      • Kotlin

        • 接受
          • RunCukesTest.kt
          • stepdefs
            • StepDefsTest.kt
      • 资源

        • 特点
          • some-feature.feature

感谢您的宝贵时间:)

最佳答案

我发现了问题。

我不得不做 mvn clean test为了重新生成已编译的测试,以便 Maven 可以使用 *Test.class 找到它们正则表达式。

最重要的属性是 <testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory><build>里面部分告诉 Maven 查看此目录以找到要执行的测试。

这是我清理过的两个 poms:

parent-pom.xml

    <properties>
<kotlin.version>1.3.40</kotlin.version>
<junit-jupiter.version>5.4.2</junit-jupiter.version>
</properties>

<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-kotlin</artifactId>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-reflect</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
<version>${kotlin.version}</version>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
</plugin>

<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
</project>

domain-pom.xml

    <properties>
<cucumber.version>4.4.0</cucumber.version>
</properties>

<dependencies>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java8</artifactId>
<version>${cucumber.version}</version>
</dependency>

<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>${cucumber.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

日志:

[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running RunCukesTest
juin 25, 2019 12:01:59 AM cucumber.runtime.java.ObjectFactoryLoader loadSingleObjectFactory
AVERTISSEMENT: Use deprecated reflections to load ObjectFactory.
Feature: Is it friday yet

Scenario: my scenario # features/some-feature.feature:3
Given today is Sunday # StepDefs.today_is_Sunday()
When I ask whether it's Friday yet # StepDefs.i_ask_whether_it_s_Friday_yet()
Then I should be told "Nope" # StepDefs.i_should_be_told(String)

1 Scenarios (1 passed)
3 Steps (3 passed)
0m0,245s

[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.251 s - in RunCukesTest

关于maven - 如何使用 'mvn test' 运行 Cucumber 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56725004/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com