简体   繁体   English

Maven项目对代码进行编译和测试的过程是什么?

[英]What is the process with Maven project to compile and test the code?

I have maven project imported in my eclipse. 我在Eclipse中导入了Maven项目。 Now I need to start making changes to it and test it with the integration test (out of App server). 现在,我需要开始对其进行更改,并使用集成测试(App服务器外部)对其进行测试。 Currently, the integration test is run out of server using openEJB container. 当前,集成测试是使用openEJB容器在服务器上用尽的。

My basic question is, what is the regular process to compile, build and test with Maven? 我的基本问题是,使用Maven进行编译,构建和测试的常规过程是什么?

  1. mvn install
  2. Maven -> Update Project. Maven->更新项目。
  3. Run my test from command line 从命令行运行我的测试

Is it how it is done? 它是怎么做到的? I am specifically interested in knowing mvn install commands. 我对了解mvn install命令特别感兴趣。 So should I do all three steps before I can test it? 那么我应该在测试之前完成所有三个步骤吗?

Example: I just wanted to print something and see what is the output. 示例:我只是想打印一些东西,然后看输出什么。 For this I guess I need to do all these steps? 为此,我想我需要执行所有这些步骤?

The openEJB container needs classes so it can load them. openEJB容器需要类,以便可以加载它们。

http://maven.apache.org/guides/MavenQuickReferenceCard.pdf上有一个很棒的Maven快速参考表。

First, you should be aware that unit tests and integration tests are separate and are run from separate plugins and at separate parts of the maven lifecycles. 首先,您应该意识到单元测试和集成测试是分开的,并且是在单独的插件中以及Maven生命周期的不同部分中运行的。 Unit tests are run with surefire and integration tests are run with failsafe . 单元测试使用surefire运行,而集成测试则使用故障安全

You want to run integration tests and the failsafe documentation says: 您要运行集成测试,并且故障安全文档说:

NOTE: when running integration tests, you should invoke maven with the (shorter to type too) 注意:在运行集成测试时,您应该使用(也要短键入)调用maven。

mvn verify

rather than trying to invoke the integration-test phase directly... 而不是尝试直接调用integration-test阶段...

This is the best way to run integration tests directly in maven . 这是直接在maven中运行集成测试的最佳方法。 It will run all the preceding steps necessary (eg: compile ) in order to run the integration tests. 为了运行集成测试,它将运行前面所有必要的步骤(例如: compile )。 It won't waste time doing an install because install happens immediately after verify . 这样做不会浪费时间,因为installverify后立即进行的。

But if you're running the tests locally, it may be a better idea to run your integration tests directly in your IDE. 但是,如果您在本地运行测试,则最好直接在IDE中运行集成测试。 That will give you a much faster feedback loop. 这将为您提供更快的反馈循环。

If it is Eclipse project the most reasonable thing is to do everything not from command line but from Eclipse. 如果它是Eclipse项目,那么最合理的方法是不通过命令行而是通过Eclipse执行所有操作。 Assuming you have m2e plugin installed, go to your_project->run as->Maven test and run it. 假设您已安装m2e插件,请转到your_project->run as->Maven test并运行它。

You dont need neither install nor package phase to run Maven tests, package will create a jar which is not needed for tests, install will copy this jar to local repo which is also useless. 您既不需要install阶段也不需要package阶段来运行Maven测试, package会创建一个测试不需要的jar, install会将这个jar复制到本地仓库中,这也是没有用的。 When Maven run tests it uses compiled classes from target dir and ignores project's jar if even it exists. 当Maven运行测试时,它将使用目标目录中的已编译类,并且即使存在,也将忽略项目的jar。

Yes, mvn isntall is the most popular option. 是的, mvn isntall是最受欢迎的选择。 It compiles, packages and tests your project. 它编译,打包和测试您的项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM