如何为运行(黄瓜)验收测试指定单独的Maven目标? [英] How do I specify a separate maven goal for running (Cucumber) acceptance tests?
问题描述
我具有以下项目结构:
MyProject
--src
--test
--acceptance
--step_definitions
--features
--unit
我希望能够在Maven中与在测试/单元中声明的单元测试分开运行我的黄瓜测试(处于测试/接受状态),以便可以在不同的CI构建计划中运行等.我正在使用黄瓜-junit,因此每个验收测试的运行者"都用JUnit编写.
I would like to be able to run my cucumber tests (in test/acceptance) separately in Maven from the unit tests declared in test/unit, so that they can be run in different CI build plans etc. I am using cucumber-junit so the 'runners' for each acceptance test are written with JUnit.
这可能吗?
推荐答案
这可能吗?
Is this possible?
是的,有可能.我相信您应该将具有以下条件的验收/集成测试与您的单元分开:
Yes, it is possible. I believe you should separate your unit from the acceptance/integration tests having:
Slightly modified folders structure for both of these, placing your integration test files in the standard location of src/it
:
MyProject/
-
src/main/java/
(SUT) -
src/test/
(单元测试代码)-
java/
-
resources/
src/main/java/
(SUT)src/test/
(unit test code)java/
resources/
-
java/
(步骤定义) -
resources/
(功能文件)
java/
(steps definitions)resources/
(feature files)
此外,根据设计,不同的Maven插件适用于单元测试和集成测试:
Moreover, by design, different Maven plugins are intended for unit and integration tests:
- 用于单元测试:
maven-surefire-plugin
- 用于接受/集成测试:
maven-failsafe-plugin
您还必须绑定执行
maven-failsafe-pulgin
.要单独运行集成测试,可以定义一个新的配置文件:You must also bind execution of
maven-failsafe-pulgin
. To run the integration tests separately, you can define a new profile:<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>
您还需要
配置插件以进行搜索测试用例的 src/it
目录树.You will also need to configure the plugin to search the
src/it
directory tree for test cases.随后可以使用以下方法运行验收测试:
The acceptance tests can be run afterwards using:
mvn clean verify -Pacceptance-tests
有关完整示例,建议您遵循 http://www.weblogism.com/item/334/integration-tests-with-cucumber-jvm-selenium-and-maven
For complete sample, I'd suggest you to follow http://www.weblogism.com/item/334/integration-tests-with-cucumber-jvm-selenium-and-maven
这篇关于如何为运行(黄瓜)验收测试指定单独的Maven目标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
-