2

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.

René
  • 63
  • 7
  • Does this answer your question? [Are test suites considered deprecated in JUnit5?](https://stackoverflow.com/questions/50565724/are-test-suites-considered-deprecated-in-junit5) – cyberbrain May 05 '22 at 13:19
  • Do you have something like this in your `build.gradle`: `tasks.named('test') { useJUnitPlatform() }` AFAIK, this is necessary with JUnit 5. :) – ahuemmer May 05 '22 at 13:25
  • @cyberbrain Nope – René May 05 '22 at 13:29
  • @ahuemmer yep --> test { useJUnitPlatform()....} Running single test methods is working – René May 05 '22 at 13:30
  • cannot reproduce any issue. add your imports, gradle config etc that is neccessary context for your question. – eis May 05 '22 at 13:31

2 Answers2

2

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'**
  
}
René
  • 63
  • 7
1

Eclipse 4.25 (part of the Eclipse 2022-09 simultaneous release) should improve the support for JUnit 5:

test suite wizard JUnit 5 support

The New JUnit Test Suite Wizard has been enhanced to now allow the creation of a JUnit 5 test suite using the @Suite annotation.

To open the New JUnit Test Suite Wizard for the current package, go to New > Other > Java > JUnit > JUnit Test Suite.

Test Suite Wizard -- https://www.eclipse.org/eclipse/news/4.25/images/test-suite-wizard-junit5.png

The result of this is:

JUnit 5 Test Suite

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250