gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 10:48:31 27 4
gpt4 key购买 nike

我有一个 gradle 项目,其中“单元测试”和“集成测试”任务定义如下:

test {
include '**/*Test.class'
}

task integrationTest(type: Test) {
include '**/*IT.class'
}

我在 IntelliJ 中创建了一个运行配置来运行所有单元测试,如图所示:

Run configuration of gradle 'test' task in intelliJ

对任务“integrationTest”做了同样的事情:

Run configuration of gradle 'test' task in intelliJ

IntelliJ“理解”测试任务并运行它以显示图形结果,如下图所示:

IntelliJ showing the results of gradle test task

运行“集成测试”任务时不会发生同样的情况。结果以文本形式显示,就像我通过命令行运行任务时一样。

最佳答案

回答我自己的问题...据我所知,您无法让 IntelliJ 运行特定任务的测试,而且模式解决方案效果不佳。

因此,我发现在 IntelliJ 中有效分离集成测试的唯一方法是使用 JUnit 类别。

  1. 创建一个接口(interface)来表示集成测试。例如:

    public interface IntegrationTest {
    }
  2. 您必须使用类别注释和创建的接口(interface)来注释每个集成测试类:

    import org.junit.experimental.categories.Category;
    import mycompany.mypackage.IntegrationTest;

    @Category(IntegrationTest.class)
    public class DbfFileProcessorIT {
    ...
    }
  3. 使用类别创建构建配置过滤: enter image description here

关于java - intelliJ 如何将 gradle 任务作为测试运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35783877/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com