简体   繁体   English

maven和单元测试 - 结合maven surefire插件和testNG eclipse插件

[英]maven and unit testing - combining maven surefire plugin AND testNG eclipse plugin

could you please share your way of unit testing in eclipse ? 请问您能否在eclipse中分享您的单元测试方式? Are you using surefire plugin, m2eclipse & maven, or only testNG eclipse plugin ? 您使用的是surefire插件,m2eclipse和maven,还是只有testNG eclipse插件? Do you combine these alternatives ? 你是否结合了这些替代品?

I'm using testNG + maven surefire-plugin and I had been using the testNG eclipse plugin a year ago so that I could see the results in testNG view. 我正在使用testNG + maven surefire-plugin,一年前我一直在使用testNG eclipse插件,这样我就可以在testNG视图中看到结果。 Then I started using Maven, but when I do "maven test phase" using m2eclipse, there is only console output and surefire reports that I can check in browser and to choose what test suite, test, or test method can be set up only via testng.xml. 然后我开始使用Maven,但是当我使用m2eclipse进行“maven测试阶段”时,只有控制台输出和surefire报告我可以在浏览器中检查并选择只能通过以下方式设置测试套件,测试或测试方法的testng.xml。

On the other hand, if you use only surefire plugin and you have some specific settings regarding classpath etc., that you rely on, then running tests via testNG eclipse plugin doesn't have to be compatible with your code. 另一方面,如果你只使用surefire插件并且你有一些关于类路径的特定设置,你依赖,那么通过testNG eclipse插件运行测试不必与你的代码兼容。 Using surefire plugin, the classpath is different - target/test-classes and target/classes - than using testNG plugin, that is using the project classpath. 使用surefire插件,类路径是不同的 - target/test-classestarget/classes - 而不是使用testNG插件,即使用项目类路径。

How do you go about what I was just talking about? 你怎么看我刚才谈到的?

Is it possible to synchronize "maven test" using m2eclipse and surefire plugin WITH testNG eclipse plugin and view ? 是否可以使用m2eclipse和surefire插件与testNG eclipse插件和视图同步“maven测试”?

EDITED: I'm also wondering, why the Maven project ("Java build path") output folder is target/classes for src/main and src/test whereas surefire plugin makes two locations target/test-classes and target/classes 编辑:我也想知道,为什么Maven项目(“Java构建路径”)输出文件夹是src/mainsrc/test target/classes ,而surefire插件使两个位置成为target/test-classestarget/classes

Thank you very much for your your opinions. 非常感谢您的意见。

Lisa, 丽莎,

You can configure the TestNG Eclipse plug-in to "watch" a test-output directory. 您可以配置TestNG Eclipse插件以“监视”测试输出目录。 Point it to target/surefire-reports and you should see your TestNG view update itself a few seconds after a Maven build terminates. 将它指向target / surefire-reports,您应该会在Maven构建终止后几秒钟看到您的TestNG视图自行更新。

I see two advantages of using the surefire plugin: 我看到使用surefire插件的两个优点:

  • Relying on the eclipse plugin only works that way when everyone in the project uses eclipse 当项目中的每个人都使用eclipse时,依赖于eclipse插件只会这样
  • Surefire plugin can run from build that are done from the continuous integration server ("jenkins") Surefire插件可以从构建运行,从持续集成服务器(“jenkins”)完成

And then if you have larger more long running (performance) test suites, you probably don't want to "block" your IDE while they run. 然后,如果您有更长的运行(性能)测试套件,您可能不希望在运行时“阻止”IDE。

I don't think it is true what you say with the different runtime classpath, I just checked myself both maven classpath and the one when test is run via testNG eclipse plugin and both are the same. 我不认为你用不同的运行时类路径说的是真的,我只是检查了自己的maven类路径和通过testNG eclipse插件运行测试时的两者都是一样的。 I think that m2eclipse plugin takes care of it. 我认为m2eclipse插件可以解决它。 It's the same even for junit testing. 对于junit测试,它也是一样的。

So afaik, there is no restriction for using testNG eclipse plugin for development and surefire plugin for instance for continuous integration as Heiko Rupp mentions. 所以afaik,没有限制使用testNG eclipse插件进行开发和surefire插件,例如Heiko Rupp提到的持续集成。 At least I have never gotten any troubles with it. 至少我从来没有遇到任何麻烦。

Just use both as you like, cheers ! 只要随心所欲,欢呼!

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

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