简体   繁体   English

intelliJ 如何运行 gradle 任务作为测试

[英]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 中创建了一个运行配置来运行所有单元测试,如图像显示:

在 IntelliJ 中运行 gradle 'test' 任务的配置

And did the same with the task 'integrationTest':对任务“integrationTest”也做了同样的事情:

在 IntelliJ 中运行 gradle 'test' 任务的配置

IntelliJ 'understands' the test task and run it showing graphical results, like in this image: IntelliJ“理解”测试任务并运行它显示图形结果,如下图所示:

IntelliJ 显示 gradle 测试任务的结果

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 类别。

  1. Create an interface to represent integration tests.创建一个接口来表示集成测试。 For example:例如:

     public interface IntegrationTest { }
  2. 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 { ... }
  3. 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.

相关问题 gradle测试任务如何运行特定的junit测试套件? - how can gradle test task run specific junit tests' suite? 如何使用 Gradle 运行任务禁用 IntelliJ 来运行我的代码? - How can I disable IntelliJ using the Gradle run task to run my code? IntelliJ IDEA:如何使用 --args 运行 gradle 应用程序插件运行任务 - IntelliJ IDEA: How to run gradle application plugin run task with --args 从intellij插件开发中运行gradle任务 - run gradle task from intellij plugin development IntelliJ JUnit 5测试运行正常作为Gradle任务。 当作为单独测试运行时,有时会出现异常:NoClassDefFoundError ... / TestExecutionListener - IntelliJ JUnit 5 test run fine as Gradle task. When run as individual test sometimes get exception: NoClassDefFoundError …/TestExecutionListener IntelliJ从Gradle导入项目后如何运行Gradle任务? - How do you run a Gradle task after IntelliJ imports a project from Gradle? Spring Boot 2.0 Gradle在IntelliJ中运行和测试 - Spring Boot 2.0 Gradle run and test in IntelliJ 如何在intellij中使用gradle运行arquillian测试,如何设置build.gradle文件? - how to run arquillian test with gradle in intellij,how to set the build.gradle file? 如果gradle项目中的测试任务失败,请运行stop tomcat任务 - run stop tomcat task if test task fails in gradle project Gradle测试任务不使用@Category和@RunWith注释运行JUnit测试 - Gradle test task does not run JUnit test with @Category and @RunWith annotations
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM