Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes sbt#121: Suite task naming no longer crashes; or mangles vintage test names #122

Merged
merged 3 commits into from
Nov 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, only junit-platform-suite-api and junit-platform-suite-engine are actually needed, if you prefer more specific dependencies

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,12 @@ 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 { }
Loading