I'm trying to migrate a Project from JUnit 4 to JUnit 5.8.2 with junit-platform-suite-api 1.8.2. We used to organize our test classes in test suites. But if I use the @Suite annotation with @SelectClasses the test runner finds no test methods at all. When running a specific test class directly everything is fine. This happens in eclipse and gradle builds.
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 looks like this
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'
}
}
Any idea how to organize the suites on class basis?
Edit:
Are test suites considered deprecated in JUnit5?
I already read this answers. As far as I see I'm using that apporach with @Suite and @SelectClasses and not the runner.
The junit-platform-suite-engine was missing...
See: 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'**
}