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-classes
和target/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/main
和src/test
是target/classes
,而surefire插件在两个位置分别是target/test-classes
和target/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 !