[英]Java How can I use a maven sub project for my integration tests?
I would like to make a separate project for my integration tests. 我想为我的集成测试创建一个单独的项目。
My current structure is like this (Maven project): 我当前的结构是这样的(Maven项目):
my-project-parent
my-project-lib (jar)
my-project-web (war)
Inside the lib sub project is the logic of my project. lib子项目内部是我项目的逻辑。 Inside the web sub project is everything that is related to my Servlets. Web子项目中包含与我的Servlet相关的所有内容。 There is still a lot of logic in there that makes it possible to handle all the different requests. 那里仍然有很多逻辑可以处理所有不同的请求。
The sub projects have unit tests. 子项目具有单元测试。 Now the unit tests and integration tests are scrambled in the project and it's hard to see if it is a unit test or an integration test. 现在,单元测试和集成测试已在项目中打乱了,很难看出它是单元测试还是集成测试。 By putting the integration tests in a separate project it also makes it possible to manage whether to run the integration tests. 通过将集成测试放在单独的项目中,还可以管理是否运行集成测试。
Because of this I would like to create another sub project with all the integration test (my-project-it). 因此,我想创建一个带有所有集成测试的子项目(my-project-it)。
So far I have a separate project called “my-project-it”. 到目前为止,我有一个单独的项目称为“ my-project-it”。 I can do some test on the lib sub project. 我可以对lib子项目进行一些测试。 The problem I ran in to was that I needed a lot of classes from my-project-web. 我遇到的问题是,我需要来自my-project-web的很多类。 I'm unable/not willing to put the war as a dependency. 我不能/不愿意把战争当作依赖。
Can anyone help me with this? 谁能帮我这个?
There is an (old but) good wiki article about integration testing with maven. 有一篇(旧但不错的) Wiki文章,介绍了与maven的集成测试。
I personally prefere a separate module that contains all the integration tests in src/it/java
. 我个人更喜欢一个单独的模块,其中包含src/it/java
中的所有集成测试。 This module can be activated with a maven build profile . 可以使用Maven构建配置文件激活该模块。 The tests are run and the results verified with the failsafe plugin . 运行测试,并使用failsafe插件验证结果。
hth, hth,
- martin -马丁
I would move all classes that are needed for my-project-it from my-project-web to my-project-jar and made it my-project-it's dependency. 我会将my-project-it所需的所有类从my-project-web移到my-project-jar,并使其成为my-project-it的依赖项。
Another option is instead of creating a separate my-project-it project create a separate package for integration tests under src/test/java and execute them with maven-failsafe-plugin http://maven.apache.org/surefire/maven-failsafe-plugin/integration-test-mojo.html 另一种选择是代替创建单独的my-project-it项目,在src / test / java下创建用于集成测试的单独程序包,然后使用maven-failsafe-plugin http://maven.apache.org/surefire/maven-执行它们failsafe-plugin / integration-test-mojo.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.