迁移到 Cucumber 后未执行任何测试 7.x
no tests executed after migrating to cucumber 7.x
我最近将我的 Spring 引导项目升级到最新的 cucumber-java (7.2.3),但我遇到了一些问题。
我能够获得预期的行为,但只能通过使用现已弃用的 @Cucumber
注释。 deprecation note 说我们应该“使用 JUnit 平台套件 运行 Cucumber”
遗憾的是,可用的示例不多(大多数参考以前的版本)。
我使用已弃用注释的工作代码很简单:
package service.test.acceptance;
import io.cucumber.junit.platform.engine.Cucumber;
@Cucumber
public class RunCucumberIntegrationTest {
}
具有这些依赖项:
testImplementation group: 'io.cucumber', name: 'cucumber-java', version: libraryVersions.cucumber
testImplementation group: 'io.cucumber', name: 'cucumber-junit', version: libraryVersions.cucumber
testImplementation group: 'io.cucumber', name: 'cucumber-spring', version: libraryVersions.cucumber
testImplementation group: 'io.cucumber', name: 'cucumber-junit-platform-engine', version: libraryVersions.cucumber
(以及 Spring 启动测试附带的 Junit 内容,所以在我的例子中 Junit 5.5.2
)
我试过了:
package service.test.acceptance;
import static io.cucumber.junit.platform.engine.Constants.GLUE_PROPERTY_NAME;
import org.junit.platform.suite.api.ConfigurationParameter;
import org.junit.platform.suite.api.IncludeEngines;
import org.junit.platform.suite.api.SelectClasspathResource;
import org.junit.platform.suite.api.Suite;
@Suite
@IncludeEngines("cucumber")
@SelectClasspathResource("service/test/acceptance")
@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value ="service.test.acceptance.integration")
public class RunCucumberIntegrationTest {
}
我需要添加这两个依赖项以便编译:
testImplementation group: 'org.junit.platform', name: 'junit-platform-suite', version: '1.8.2'
testImplementation group: 'org.junit.platform', name: 'junit-platform-suite-api', version: '1.8.2'
我的步骤定义在 service.test.acceptance.integration
包中(在 src/test/java
中),而我的功能文件在 service/test/acceptance
文件夹中(在 src/test/resources
中)。
当我 运行 gradlew test
时,构建是绿色的,但没有执行任何测试,也没有任何警告或任何东西。
知道我错过了什么吗?
你可以尝试使用以下依赖项
<properties>
<junit-jupiter.version>5.8.2</junit-jupiter.version>
<cucumber.version>7.2.3</cucumber.version>
</properties>
....
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-suite</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java8</artifactId>
<version>${cucumber.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit-platform-engine</artifactId>
<version>${cucumber.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-spring</artifactId>
<version>${cucumber.version}</version>
<scope>test</scope>
</dependency>
@Suite
@IncludeEngines("cucumber")
@SelectClasspathResource("features/example.feature")
@ConfigurationParameters({
@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "packagename.cucumber"),
@ConfigurationParameter(key = FILTER_TAGS_PROPERTY_NAME, value = "@Example"),
@ConfigurationParameter(key = JUNIT_PLATFORM_NAMING_STRATEGY_PROPERTY_NAME, value = "long"),
@ConfigurationParameter(key = PLUGIN_PUBLISH_QUIET_PROPERTY_NAME, value = "true"),
@ConfigurationParameter(key = PLUGIN_PROPERTY_NAME, value = "json:target/cucumber/cucumber.json")
})
public class RunCucumberExampleTest {}
并且由于您使用的是 spring(如果您使用的是 lambda),您可以使用
这样的配置
@SpringBootTest(classes = ExampleApplication.class, webEnvironment = RANDOM_PORT)
@CucumberContextConfiguration
@ActiveProfiles("test")
public class SpringCucumberTestConfig {}
多亏了 @paul58914080 and @m-p-korstanje 的建议,我才能让它工作:非常感谢!
确实是我用的junit和cucumber版本不兼容
这就是我最终得到的:
//override the junit version that comes with my version of Spring, and pick one compatible with Cucumber
ext['junit-jupiter.version'] = '5.8.2'
然后在依赖块中:
testImplementation(platform("io.cucumber:cucumber-bom:7.2.3"))
testImplementation group: 'io.cucumber', name: 'cucumber-java'
testImplementation group: 'io.cucumber', name: 'cucumber-spring'
testImplementation group: 'io.cucumber', name: 'cucumber-junit-platform-engine'
testImplementation group: 'org.junit.platform', name: 'junit-platform-suite'
//this one was already there.. just mentioning it for sake of being exhaustive
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
我不需要触摸我的 RunCucumberIntegrationTest class。
我最近将我的 Spring 引导项目升级到最新的 cucumber-java (7.2.3),但我遇到了一些问题。
我能够获得预期的行为,但只能通过使用现已弃用的 @Cucumber
注释。 deprecation note 说我们应该“使用 JUnit 平台套件 运行 Cucumber”
遗憾的是,可用的示例不多(大多数参考以前的版本)。
我使用已弃用注释的工作代码很简单:
package service.test.acceptance;
import io.cucumber.junit.platform.engine.Cucumber;
@Cucumber
public class RunCucumberIntegrationTest {
}
具有这些依赖项:
testImplementation group: 'io.cucumber', name: 'cucumber-java', version: libraryVersions.cucumber
testImplementation group: 'io.cucumber', name: 'cucumber-junit', version: libraryVersions.cucumber
testImplementation group: 'io.cucumber', name: 'cucumber-spring', version: libraryVersions.cucumber
testImplementation group: 'io.cucumber', name: 'cucumber-junit-platform-engine', version: libraryVersions.cucumber
(以及 Spring 启动测试附带的 Junit 内容,所以在我的例子中 Junit 5.5.2
)
我试过了:
package service.test.acceptance;
import static io.cucumber.junit.platform.engine.Constants.GLUE_PROPERTY_NAME;
import org.junit.platform.suite.api.ConfigurationParameter;
import org.junit.platform.suite.api.IncludeEngines;
import org.junit.platform.suite.api.SelectClasspathResource;
import org.junit.platform.suite.api.Suite;
@Suite
@IncludeEngines("cucumber")
@SelectClasspathResource("service/test/acceptance")
@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value ="service.test.acceptance.integration")
public class RunCucumberIntegrationTest {
}
我需要添加这两个依赖项以便编译:
testImplementation group: 'org.junit.platform', name: 'junit-platform-suite', version: '1.8.2'
testImplementation group: 'org.junit.platform', name: 'junit-platform-suite-api', version: '1.8.2'
我的步骤定义在 service.test.acceptance.integration
包中(在 src/test/java
中),而我的功能文件在 service/test/acceptance
文件夹中(在 src/test/resources
中)。
当我 运行 gradlew test
时,构建是绿色的,但没有执行任何测试,也没有任何警告或任何东西。
知道我错过了什么吗?
你可以尝试使用以下依赖项
<properties>
<junit-jupiter.version>5.8.2</junit-jupiter.version>
<cucumber.version>7.2.3</cucumber.version>
</properties>
....
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-suite</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java8</artifactId>
<version>${cucumber.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit-platform-engine</artifactId>
<version>${cucumber.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-spring</artifactId>
<version>${cucumber.version}</version>
<scope>test</scope>
</dependency>
@Suite
@IncludeEngines("cucumber")
@SelectClasspathResource("features/example.feature")
@ConfigurationParameters({
@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "packagename.cucumber"),
@ConfigurationParameter(key = FILTER_TAGS_PROPERTY_NAME, value = "@Example"),
@ConfigurationParameter(key = JUNIT_PLATFORM_NAMING_STRATEGY_PROPERTY_NAME, value = "long"),
@ConfigurationParameter(key = PLUGIN_PUBLISH_QUIET_PROPERTY_NAME, value = "true"),
@ConfigurationParameter(key = PLUGIN_PROPERTY_NAME, value = "json:target/cucumber/cucumber.json")
})
public class RunCucumberExampleTest {}
并且由于您使用的是 spring(如果您使用的是 lambda),您可以使用
这样的配置@SpringBootTest(classes = ExampleApplication.class, webEnvironment = RANDOM_PORT)
@CucumberContextConfiguration
@ActiveProfiles("test")
public class SpringCucumberTestConfig {}
多亏了 @paul58914080 and @m-p-korstanje 的建议,我才能让它工作:非常感谢!
确实是我用的junit和cucumber版本不兼容
这就是我最终得到的:
//override the junit version that comes with my version of Spring, and pick one compatible with Cucumber
ext['junit-jupiter.version'] = '5.8.2'
然后在依赖块中:
testImplementation(platform("io.cucumber:cucumber-bom:7.2.3"))
testImplementation group: 'io.cucumber', name: 'cucumber-java'
testImplementation group: 'io.cucumber', name: 'cucumber-spring'
testImplementation group: 'io.cucumber', name: 'cucumber-junit-platform-engine'
testImplementation group: 'org.junit.platform', name: 'junit-platform-suite'
//this one was already there.. just mentioning it for sake of being exhaustive
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
我不需要触摸我的 RunCucumberIntegrationTest class。