Maven和单元测试-结合使用Maven surefire插件和testNG eclipse插件 [英] maven and unit testing - combining maven surefire plugin AND testNG eclipse plugin

查看:298
本文介绍了Maven和单元测试-结合使用Maven surefire插件和testNG eclipse插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

能否请您分享在Eclipse中进行单元测试的方式?您是否正在使用surefire插件m2eclipse& Maven,还是只有testNG eclipse插件?您是否结合了这些替代方案?

could you please share your way of unit testing in eclipse ? Are you using surefire plugin, m2eclipse & maven, or only testNG eclipse plugin ? Do you combine these alternatives ?

我正在使用testNG + maven surefire-plugin,一年前我一直在使用testNG eclipse插件,以便可以在testNG视图中查看结果.然后我开始使用Maven,但是当我使用m2eclipse进行"maven测试阶段"时,只有控制台输出和surefire报告,我可以在浏览器中检入并选择只能通过以下方法设置的测试套件,测试或测试方法: testng.xml.

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. 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.

另一方面,如果仅使用surefire插件,并且您依赖于某些有关类路径等的特定设置,则通过testNG eclipse插件运行测试不必与您的代码兼容.使用surefire插件时,类路径-target/test-classestarget/classes-与使用testNG插件时不同,即使用项目类路径.

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. Using surefire plugin, the classpath is different - target/test-classes and target/classes - than using testNG plugin, that is using the project classpath.

您如何处理我刚才所说的内容?

是否可以使用m2eclipse和surefire插件与testNG eclipse插件同步行家测试"并查看?

我也想知道,为什么Maven项目("Java构建路径")输出文件夹对于src/mainsrc/testtarget/classes,而surefire插件在两个位置分别是target/test-classestarget/classes

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类路径和通过testNG运行测试时的路径. eclipse插件和两者都相同.我认为m2eclipse插件可以解决这个问题.即使是junit测试也是如此.

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. I think that m2eclipse plugin takes care of it. It's the same even for junit testing.

因此afaik,如Heiko Rupp所提到的,使用testNG eclipse插件进行开发和使用surefire插件进行持续集成没有任何限制.至少我从来没有遇到任何麻烦.

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. At least I have never gotten any troubles with it.

只要使用就可以,加油!

Just use both as you like, cheers !

这篇关于Maven和单元测试-结合使用Maven surefire插件和testNG eclipse插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆