Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jodersky committed Nov 18, 2024
1 parent 6fcd06b commit 3d5f4a5
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
6 changes: 6 additions & 0 deletions scalalib/test/resources/junit5/test/src/qux/FooTests.java
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 {

}
17 changes: 17 additions & 0 deletions scalalib/test/resources/junit5/test/src/qux/QuxTests.java
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{}
30 changes: 30 additions & 0 deletions scalalib/test/src/mill/javalib/junit5/JUnit5Tests.scala
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"))
}
}
}

0 comments on commit 3d5f4a5

Please sign in to comment.