【问题标题】:Running JUnit Tests in IntelliJ with category annotations使用类别注释在 IntelliJ 中运行 JUnit 测试
【发布时间】:2018-09-20 02:22:24
【问题描述】:

我正在尝试在 使用 IntelliJ 的模块中运行带有注释 @FastTests 的所有测试。我可以使用 JUnit 配置和测试类型 All In Package 和相关的包名称来运行模块中的所有测试。

当我尝试通过选择 Category 测试类型 JUnit 配置并选择 Search For Tests: Across Module DependenciesSearch for Tests: In Single module 来运行单个类别时,我得到 No Tests were found

有没有办法在 intellij 中运行带有单个类别注解的 JUnit 测试?

干杯

【问题讨论】:

  • 您找到解决方案了吗?您还需要这方面的帮助吗?

标签: java intellij-idea junit


【解决方案1】:

这适用于我使用 Intellij IDEA 2018.1:

将类别标记定义为接口:

public interface FastTests { /* category marker */ }

和测试类或方法注释如下:

import cu.nicolau.sircap.nomencladores.FastTests;
import org.junit.Test;
import org.junit.experimental.categories.Category;

public class NomencladorServiceImplTest {    
    @Test
    @Category(FastTests.class)
    public void categoryTest() {
        ...
    }    
}

使用JUnit 5@Category 注释被更灵活的@Tag 注释取代。

如果您将 migrating 考虑到 JUnit 5,this blog 可能是一个不错的起点。此外,thisthis 答案可以告诉您如何使用 Intellij IDEA 或 Maven 根据其标签过滤测试执行。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-23
    • 2015-09-26
    相关资源
    最近更新 更多