java - Junit 5 测试套件

标签 java junit5 junit-jupiter

我正在尝试使用 junit-platform-suite-api 1.8.2 将项目从 JUnit 4 迁移到 JUnit 5.8.2。我们曾经在测试套件中组织我们的测试类。但是,如果我将 @Suite 注释与 @SelectClasses 一起使用,测试运行程序根本找不到测试方法。当直接运行特定的测试类时,一切都很好。这发生在 eclipse 和 gradle 构建中。

import org.junit.platform.suite.api.SelectClasses;
import org.junit.platform.suite.api.Suite;

@Suite
@SelectClasses({
    TestA.class
})
public class ImportantTestSuite {
}
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Assertions;

public class TestA {

    @Test
    public void reallyImportantTest() {
        assertEquals(2, 1 + 1)
    }

}

build.gradle 看起来像这样

plugins {
  id 'application'
}

dependencies {
  testImplementation "org.junit.jupiter:junit-jupiter-api:${junitVersion}"
  testImplementation 'org.junit.platform:junit-platform-suite-api:1.8.2'
  testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${junitVersion}"
}

test {
    useJUnitPlatform()
    minHeapSize = '1024m'
    maxHeapSize = '1024m'
    include '**/*ImportantTestSuite*'
    ignoreFailures = true
    testLogging {
      exceptionFormat 'full'
      events 'passed', 'skipped', 'failed'
    }
  }

知道如何按类(class)组织套房吗?

编辑:

Are test suites considered deprecated in JUnit5?

我已经阅读了这个答案。据我所知,我将该apporach与@Suite和@SelectClasses一起使用,而不是与运行者一起使用。

最佳答案

junit-platform-suite-engine 丢失...

参见:https://junit.org/junit5/docs/current/user-guide/index.html#junit-platform-suite-engine

dependencies {
  testImplementation "org.junit.jupiter:junit-jupiter-api:${junitVersion}"
  testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${junitVersion}"
  testImplementation 'org.junit.platform:junit-platform-suite-api:1.8.2'
  **testRuntimeOnly 'org.junit.platform:junit-platform-suite-engine:1.8.2'**
  
}

关于java - Junit 5 测试套件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72127811/

相关文章:

java - Java Swing 上的 Facebook 共享按钮

java - Sonar分析导致通过Jenkins在maven项目上索引0个文件

java - Java 程序终止时未能关闭文件有什么危害吗?

java - Java中的参数化@Interface注解

java - Assertj 3.16.1 中是否弃用了方法 "hasOnlyElementsOfType"

java - 警告 : unknown enum constant Status. 稳定

Kotlin MockK : io. mockk.MockKException:找不到答案

java - 使用 JavaMail API 时未收到任何响应

maven - 通过 Maven 执行测试时 @DisplayName 不起作用