Skip to content

Commit

Permalink
Fixes #121: Suite task naming no longer crashes; or mangles vintage t…
Browse files Browse the repository at this point in the history
…est names (#122)

* Fixes #121: Task naming no longer crashes for tests in Suites, and Vintage tests in Suites have their names properly formatted.

* Updated formatting for sbt-java-formatter
  • Loading branch information
dji authored Nov 2, 2024
1 parent 00de471 commit 359679d
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 3 deletions.
1 change: 1 addition & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ lazy val library = (project in file("src/library"))
testInterface,
junitJupiterParams % Test,
junitVintageEngine % Test,
junitPlatformSuite % Test,
hamcrestLibrary % Test,
mockitoCore % Test,
junit4Interface % Test,
Expand Down
1 change: 1 addition & 0 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ object Dependencies {
val testInterface = "org.scala-sbt" % "test-interface" % testInterfaceVer
val junitJupiterParams = "org.junit.jupiter" % "junit-jupiter-params" % junitJupiterVer
val junitVintageEngine = "org.junit.vintage" % "junit-vintage-engine" % junitVintageVer
val junitPlatformSuite = "org.junit.platform" % "junit-platform-suite" % junitPlatformVer
val hamcrestLibrary = "org.hamcrest" % "hamcrest-library" % "3.0"
val mockitoCore = "org.mockito" % "mockito-core" % "4.11.0"
val junit4Interface = "com.github.sbt" % "junit-interface" % "0.13.3"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,13 @@ public String format() {

final List<TestIdentifier> path = getPath(testPlan, identifier);

testEngine = UniqueId.parse(identifier.getUniqueId()).getEngineId().orElse(null);
// When run as part of a suite, the suite engine is the first segment, so look further
testEngine =
UniqueId.parse(identifier.getUniqueId()).getSegments().stream()
.filter(segment -> segment.getType().equals("engine"))
.map(Segment::getValue)
.reduce((first, last) -> last)
.orElse(null);

return path.stream()
.skip(1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ static TaskName of(String testSuite, TestIdentifier identifier) {
if (testSource instanceof MethodSource) {

MethodSource methodSource = (MethodSource) testSource;
result.nestedSuiteId = nestedSuiteId(testSuite, methodSource.getClassName());
result.nestedSuiteId = nestedSuiteId(removedJunit5SuiteName, methodSource.getClassName());
result.invocation = invocation(identifier, UniqueId.parse(identifier.getUniqueId()));
result.testName =
testName(methodSource.getMethodName(), methodSource.getMethodParameterTypes());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ public static Object[][] samples() {
{"jupiter.samples.SimpleTests", "testWithParameter", "#{1}(org.junit.jupiter.api.TestInfo)"},
{"jupiter.samples.VintageTests", "vintageTestMethod", "#{1}"},
{"jupiter.samples.VintageEnclosedTests", "testMethod", "$NestedTest#{1}"},
{"jupiter.samples.VintageParameterizedTests", "testParameters", "#{1}[A-65]"}
{"jupiter.samples.VintageParameterizedTests", "testParameters", "#{1}[A-65]"},
{"jupiter.samples.SuiteTest", "firstTestMethod", "jupiter.samples.SimpleTests#{1}()"},
{"jupiter.samples.SuiteTest", "vintageTestMethod", "jupiter.samples.VintageTests#{1}"}
};

// @formatter:on
Expand Down
9 changes: 9 additions & 0 deletions src/library/src/test/java/jupiter/samples/SuiteTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package jupiter.samples;

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

/** Sample test methods for the junit-platform-suite-engine. */
@Suite
@SelectClasses({SimpleTests.class, VintageTests.class})
public class SuiteTest {}

0 comments on commit 359679d

Please sign in to comment.