java 如何在 Eclipse 上运行 Maven 单元测试 (testng)?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15581200/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 20:08:42  来源:igfitidea点击:

How to run Maven unit test (testng) on Eclipse?

javamaventestng

提问by codereviewanskquestions

I have a Maven project and I have included some unit tests. I can run those unit tests from command line using

我有一个 Maven 项目,并且包含了一些单元测试。我可以使用命令行运行这些单元测试

mvn test -Dtest=AppTest

It will run the unit test (AppTest class) without any problems. But if I tried to run the test on Eclipse as JUnitTest, I got an error saying

它将毫无问题地运行单元测试(AppTest 类)。但是如果我尝试在 Eclipse 上以 JUnitTest 的形式运行测试,我会收到一条错误消息

"No Tests found with test runner 'JUnit 3'"

I know the test (AppTest) is not a JUnit test but I didn't see "maven" option if I right clicked on the test class.

我知道测试 (AppTest) 不是 JUnit 测试,但是如果我右键单击测试类,我没有看到“maven”选项。

Do you know how I could run the tests on Eclipse?

你知道我如何在 Eclipse 上运行测试吗?

采纳答案by niharika_neo

If those are testng tests, then you can download the eclipse plugin for TestNG and right click and run them as test class. Testng plugin here

如果这些是 testng 测试,那么您可以下载 TestNG 的 eclipse 插件并右键单击并将它们作为测试类运行。测试插件在这里

If you want to run the command line way of maven, you would need the maven plugin for eclipse from hereThen you can right click your project and you should see an option of Run As -> Maven Test. You would need to set relevant arguments in the surefire plugin of pom or use run configuration to specify parameters like you did in -Dtest

如果你想运行 maven 的命令行方式,你需要这里的eclipse 的 maven 插件 然后你可以右键单击你的项目,你应该看到一个 Run As -> Maven Test 选项。您需要在 pom 的 surefire 插件中设置相关参数或使用运行配置来指定参数,就像您在 -Dtest 中所做的那样

I would suggest the testng plugin which would be simpler to just select the class and run the class or a single case or a package even.

我建议使用 testng 插件,它可以更简单地选择类并运行类或单个案例或包。