如何让Eclipse运行我的所有Groovy单元测试?

时间:2022-04-01 11:26:44

I have an Eclipse project with many unit tests written in Groovy. I can run the tests in each individual class using Eclipse's GUnit run configuration. I open this configuration, select the "Run a single test" radio button, and select the class whose tests I want to run. This works fine, however I want to run all of the tests in the the project at once.

我有一个Eclipse项目,其中包含许多用Groovy编写的单元测试。我可以使用Eclipse的GUnit运行配置在每个单独的类中运行测试。我打开此配置,选择“运行单个测试”单选按钮,然后选择要运行其测试的类。这工作正常,但我想立即运行项目中的所有测试。

When I open my run configuration, select the "Run all tests in the selected project, package or source folder" radio button and select my project, Eclipse gives the error "No tests found with test runner 'JUnit 4'."

当我打开运行配置时,选择“在所选项目,包或源文件夹中运行所有测试”单选按钮并选择我的项目,Eclipse会给出错误“找不到测试运行器'JUnit 4'的测试。”

How do I get Eclipse to run all of the tests in my project?

如何让Eclipse运行我的项目中的所有测试?

2 个解决方案

#1


Please upgrade to the Alpha version of the groovy-eclipse plugin V2. You can run all unit tests in a project by right-clicking and selecting Run as->JUnit. In the new version of the plugin, Junit tests are treated identically whether they are written in Java or Groovy.

请升级到groovy-eclipse插件V2的Alpha版本。您可以通过右键单击并选择Run as-> JUnit来运行项目中的所有单元测试。在新版本的插件中,Junit测试的处理方式完全相同,无论是用Java还是Groovy编写的。

#2


Figured this out with the help of the documentation. Groovy has a utility class groovy.util.AllTestSuite. I created a new GUnit run configuration with this as my test class and added VM arguments like this:

在文档的帮助下计算出来。 Groovy有一个实用程序类groovy.util.AllTestSuite。我创建了一个新的GUnit运行配置,将其作为我的测试类,并添加了如下所示的VM参数:

-Dgroovy.test.dir=src -Dgroovy.test.pattern=**/*Tests.groovy

I also had to add ant.jar and ant-launcher.jar to the configuration classpath. That configuration happily runs all my tests.

我还必须将ant.jar和ant-launcher.jar添加到配置类路径中。这个配置愉快地运行我的所有测试。

#1


Please upgrade to the Alpha version of the groovy-eclipse plugin V2. You can run all unit tests in a project by right-clicking and selecting Run as->JUnit. In the new version of the plugin, Junit tests are treated identically whether they are written in Java or Groovy.

请升级到groovy-eclipse插件V2的Alpha版本。您可以通过右键单击并选择Run as-> JUnit来运行项目中的所有单元测试。在新版本的插件中,Junit测试的处理方式完全相同,无论是用Java还是Groovy编写的。

#2


Figured this out with the help of the documentation. Groovy has a utility class groovy.util.AllTestSuite. I created a new GUnit run configuration with this as my test class and added VM arguments like this:

在文档的帮助下计算出来。 Groovy有一个实用程序类groovy.util.AllTestSuite。我创建了一个新的GUnit运行配置,将其作为我的测试类,并添加了如下所示的VM参数:

-Dgroovy.test.dir=src -Dgroovy.test.pattern=**/*Tests.groovy

I also had to add ant.jar and ant-launcher.jar to the configuration classpath. That configuration happily runs all my tests.

我还必须将ant.jar和ant-launcher.jar添加到配置类路径中。这个配置愉快地运行我的所有测试。