-
-
Notifications
You must be signed in to change notification settings - Fork 369
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
junit5: override test discovery (#3983)
This changes discovery of test classes for Junit5, to be in line with that of sbt-jupiter-interface. Closes #3910
- Loading branch information
Showing
4 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package qux; | ||
|
||
// this class should not be detected as a test | ||
public class FooTests { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package qux; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
public class QuxTests { | ||
|
||
@Test | ||
public void hello() { | ||
assertTrue(true); | ||
} | ||
|
||
} | ||
|
||
// this class should not be detected as a test | ||
class Dummy{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package mill.javalib.junit5 | ||
|
||
import mill.scalalib.JavaModule | ||
import mill.scalalib.TestModule | ||
import mill.testkit.{TestBaseModule, UnitTester} | ||
import utest._ | ||
|
||
object JUnit5Tests extends TestSuite { | ||
|
||
object module extends TestBaseModule with JavaModule { | ||
object test extends JavaTests with TestModule.Junit5 | ||
} | ||
|
||
val testModuleSourcesPath = os.Path(sys.env("MILL_TEST_RESOURCE_DIR")) / "junit5" | ||
|
||
def tests = Tests { | ||
test("discovery") { | ||
val eval = UnitTester(module, testModuleSourcesPath) | ||
val res = eval(module.test.discoveredTestClasses) | ||
assert(res.isRight) | ||
assert(res.toOption.get.value == Seq("qux.QuxTests")) | ||
} | ||
test("execution") { | ||
val eval = UnitTester(module, testModuleSourcesPath) | ||
val res = eval(module.test.test("")) | ||
assert(res.isRight) | ||
assert(res.toOption.get.value._2.forall(_.fullyQualifiedName == "qux.QuxTests")) | ||
} | ||
} | ||
} |