简体   繁体   English

Java如何将maven子项目用于集成测试?

[英]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.

相关问题 在我的testNG集成测试中,我可以多次使用@factory吗(使用Jenkins和Maven进行构建)? - In my testNG integration tests can I use @factory more than once (using Jenkins and Maven for my builds)? 如何让我的 Maven 集成测试运行 - How do I get my Maven Integration tests to run 如何在我的 Java 项目中使用 Maven 以及为什么? - How to use Maven in my Java Project and Why? 如何在maven中为Java项目组织单元,集成,e2e测试文件夹结构? - How to organise unit, integration, e2e tests folder structure in maven for a Java project? 如何在这个java项目中使用maven - How do I use maven with this java project 如何将Maven项目用作另一个Maven项目的依赖项? - How can I use a Maven project as a dependency to another Maven project? 我如何在构建阶段只运行单元测试而不是集成测试 maven - How can i run only the unit tests not the integration tests on build phase with maven 如何在 Maven 项目中的单元测试上运行 IntelliJ 调试器? - How can I run the IntelliJ debugger on unit tests in a Maven project? 如何让我的子项目从多模块Maven项目中的超级项目继承依赖项版本? - How can I get my sub projects to inherit dependency versions from the super project in a multi module Maven project? 如何让eclipse在我的m2e maven项目中检测到新的Java类? - How can I make eclipse detect my new java class in my m2e maven project?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM