如何使用maven-surefire-plugin在同一项目中执行JUnit和TestNG测试?

如何使用maven-surefire-plugin在同一项目中执行JUnit和TestNG测试?

问题描述:

现在我同时拥有两种类型的测试,但是当我说"mvn test"时,它仅执行TestNG测试,而不执行Junit.我要一个接一个地执行.有任何想法吗?

Right now I have both type of tests but when I say "mvn test" it only executes TestNG tests and not Junit. I want to execute both one after another. Any Idea ?

有一个尚待解决的问题 s,所以没有优雅的方法可以做到这一点.

There is an open issue for this, so there's no elegant way to do this.

选择一个框架并坚持下去会容易得多.

It would be far simpler for you to pick a framework and stick with it.

我的上一个答案不起作用,因为您不能在执行中指定依赖项. 我已经尝试了几种方法,但是我能管理的最好方法是为TestNG依赖关系创建一个配置文件,以便您可以在TestNG和JUnit测试之间切换,似乎没有办法同时运行TestNG和Junit 4测试

My previous answer doesn't work because you can't specify dependencies in the execution. I've tried a few approaches, but the best I can manage is to create a profile for the TestNG dependency so you can toggle between TestNG and JUnit testing, there doesn't seem to be a means to run both TestNG and Junit 4 tests.

要注意的另一点:您可以从TestNG启动JUnit测试 ,但我认为这仅适用于JUnit 3测试.

One other point to note: You can launch your JUnit tests from TestNG, but I think this only works for JUnit 3 tests.