我有以下项目结构:
MyProject
--src
--test
--acceptance
--step_definitions
--features
--unit
我希望能够在 Maven 中与 test/unit 中声明的单元测试分开运行我的黄瓜测试(在测试/验收中),以便它们可以在不同的 CI 构建计划等中运行。我正在使用 cucumber-junit 所以每个验收测试的“运行程序”都是用 JUnit 编写的。
这可能吗?
这可能吗?
对的,这是可能的。我认为您应该将您的单元与验收/集成测试分开:
轻微地修改的文件夹结构对于这两个,将您的集成测试文件放在标准位置 https://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html of src/it
:
MyProject/
-
src/main/java/
(SUT)
-
src/test/
(unit test code)
-
src/it/
(acceptance/integration tests)
-
java/
(步骤定义)
-
resources/
(特征文件)
此外,根据设计,不同的 Maven 插件用于单元和集成测试:
- 对于单元测试:maven-surefire-plugin http://maven.apache.org/surefire/maven-surefire-plugin
- 对于验收/集成测试:maven-failsafe-plugin http://maven.apache.org/surefire/maven-failsafe-plugin/
你还必须绑定执行maven-failsafe-pulgin https://stackoverflow.com/a/33923836/545127。要单独运行集成测试,您可以定义一个新的配置文件:
<profiles>
<profile>
<id>acceptance-tests</id>
<build>
<plugins>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.12</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
您还需要配置插件进行搜索 https://stackoverflow.com/questions/38398323/configuring-maven-failsafe-plugin-to-correctly-find-integration-tests the src/it
测试用例的目录树。
之后可以使用以下命令运行验收测试:
mvn clean verify -Pacceptance-tests
对于完整的示例,我建议您遵循http://www.weblogism.com/item/334/integration-tests-with-cucumber-jvm-selenium-and-maven http://www.weblogism.com/item/334/integration-tests-with-cucumber-jvm-selenium-and-maven
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)