[英]How can intelliJ run gradle task as test
I have a gradle project with "unit test" and "integration tests" tasks defined as follows:我有一个带有“单元测试”和“集成测试”任务的 gradle 项目,其定义如下:
test {
include '**/*Test.class'
}
task integrationTest(type: Test) {
include '**/*IT.class'
}
I created a run configuration in IntelliJ to run all unit tests like image shows:我在 IntelliJ 中创建了一个运行配置来运行所有单元测试,如图像显示:
And did the same with the task 'integrationTest':对任务“integrationTest”也做了同样的事情:
IntelliJ 'understands' the test task and run it showing graphical results, like in this image: IntelliJ“理解”测试任务并运行它显示图形结果,如下图所示:
The same doesn't happen when it runs the 'integrationTest' task.运行“integrationTest”任务时不会发生同样的情况。 The results are shown in text, like when I run the task by command line.
结果以文本形式显示,就像我通过命令行运行任务一样。
Answering my own question... As far as I know you can't make IntelliJ to run tests of a specific task and the Pattern solution doesn't work so well.回答我自己的问题...据我所知,您无法让 IntelliJ 运行特定任务的测试,并且模式解决方案效果不佳。
So, the only way I found to effectively separate integration tests in IntelliJ was with the use of a JUnit Category.因此,我发现在 IntelliJ 中有效分离集成测试的唯一方法是使用 JUnit 类别。
Create an interface to represent integration tests.创建一个接口来表示集成测试。 For example:
例如:
public interface IntegrationTest { }
You have to annotate every integration test class with the category annotation and the created interface:您必须使用类别注释和创建的接口来注释每个集成测试类:
import org.junit.experimental.categories.Category; import mycompany.mypackage.IntegrationTest; @Category(IntegrationTest.class) public class DbfFileProcessorIT { ... }
Create a build configuration filtering with Category:使用类别创建构建配置过滤:
Just add idea plugin to gradle works for me只需将idea插件添加到gradle即可为我工作
plugins {
idea
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.