Skip to content

Commit 9e8941e

Browse files
authored
Add more docs for selecting individual test cases (#6089)
1 parent 75875ba commit 9e8941e

File tree

8 files changed

+81
-11
lines changed

8 files changed

+81
-11
lines changed

example/javalib/config/2-testing/build.mill

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,25 @@ Test qux.QuxIntegrationTests#helloworld() finished...
1414

1515
*/
1616
//// SNIPPET:TEST
17+
18+
//// SNIPPET:RUNSINGLE
19+
// e.g. the https://github.com/sbt/sbt-jupiter-interface[Junit5/Jupiter test interface]
20+
// used in this example lets you pass in a selector to decide which individual test
21+
// case to run via:
22+
23+
/** Usage
24+
25+
> ./mill test 'qux.QuxTests.*'
26+
...qux.QuxTests...hello...
27+
...qux.QuxTests...world...
28+
Test run finished: 0 failed, 0 ignored, 2 total...
29+
30+
> ./mill test 'qux.QuxTests.hello*'
31+
...qux.QuxTests...hello...
32+
Test run finished: 0 failed, 0 ignored, 1 total...
33+
34+
*/
35+
36+
// Note the trailing `*` that is necessary for the per-test selector to match.
37+
38+
//// SNIPPET:END
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
extends: [build.JavaTests, mill.javalib.TestModule.Junit5]
2-
mvnDeps: [org.junit.jupiter:junit-jupiter:5.8.2]
2+
mvnDeps: [
3+
org.junit.jupiter:junit-jupiter-api:5.14.1,
4+
org.junit.platform:junit-platform-launcher:1.14.1,
5+
com.github.sbt.junit:jupiter-interface:0.16.0
6+
]

example/javalib/testing/1-test-suite/build.mill

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,21 @@ object bar extends JavaModule {
2929
}
3030

3131
//// SNIPPET:RUNSINGLE
32+
// e.g. the https://github.com/sbt/junit-interface[Junit4 test interface]
33+
// used in this example lets you pass in a selector to decide which individual test to run via:
34+
35+
/** Usage
36+
37+
> ./mill foo.test 'foo.FooMoreTests.*'
38+
...foo.FooMoreTests...hello ...
39+
Test run finished: 0 failed, 0 ignored, 3 total...
40+
41+
> ./mill bar.test 'bar.BarTests.hello*'
42+
...bar.BarTests...hello ...
43+
Test run bar.BarTests finished: 0 failed, 0 ignored, 1 total...
44+
45+
*/
46+
47+
// Note the trailing `*` that is necessary for the per-test selector to match.
48+
49+
//// SNIPPET:END

example/kotlinlib/config/2-testing/build.mill

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@ Test qux.QuxIntegrationTests helloworld finished...
1414

1515
*/
1616
//// SNIPPET:TEST
17+
//// SNIPPET:RUNSINGLE
18+
//// SNIPPET:END

example/kotlinlib/testing/1-test-suite/build.mill

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,4 @@ object bar extends KotlinModule {
4545
}
4646

4747
//// SNIPPET:RUNSINGLE
48+
//// SNIPPET:END

example/scalalib/config/2-testing/build.mill

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,26 @@
3434
*/
3535
//// SNIPPET:END
3636

37+
// === Selecting Test Classes or Test Cases
38+
// To select tests to run on a class or test-case granularity, you can pass parameters
39+
// to the test framework at the command line.
40+
41+
//// SNIPPET:RUNSINGLE
42+
// e.g. {utest-github-url}[uTest framework] used in this example lets you pass in a
43+
// selector to decide which individual test case to run via:
44+
/** Usage
45+
46+
> ./mill test qux.QuxTests
47+
...qux.QuxTests...hello ...
48+
...qux.QuxTests...world ...
49+
Tests: 2, Passed: 2, Failed: 0
50+
51+
> ./mill test qux.QuxTests.hello
52+
...qux.QuxTests...hello ...
53+
Tests: 1, Passed: 1, Failed: 0
54+
55+
*/
56+
3757
// For more details on testing in Mill, see
3858
// xref:{language-small}lib/testing.adoc[Testing {language} Projects]
59+
//// SNIPPET:END

example/scalalib/testing/1-test-suite/build.mill

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ compiling 2 ... source...
4646

4747
*/
4848

49+
// === Common Test Framework Support
50+
//
4951
// For convenience, you can also use one of the predefined test frameworks:
5052
//
5153
// * `TestModule.Junit4`, using https://github.com/sbt/junit-interface[sbt/junit-interface]
@@ -94,6 +96,8 @@ object bar extends ScalaModule {
9496

9597
*/
9698

99+
// === Running Tests
100+
//
97101
// Mill provides three ways of running tests
98102
/** Usage
99103
> ./mill foo.test
@@ -130,25 +134,22 @@ object bar extends ScalaModule {
130134
// xref:javalib/module-config.adoc#_classpath_and_filesystem_resources[Classpath and Filesystem Resources]
131135
// for more details.
132136
//
133-
// If you want to pass any arguments to the test framework, you can pass them after
134-
// `foo.test` in the command line. e.g. {utest-github-url}[uTest]
135-
// lets you pass in a selector to decide which test to run, which in Mill would be:
137+
// === Selecting Test Classes or Test Cases
138+
// Note that `testOnly` only works at a class-level granularity. To select tests to run on a
139+
// finer-grained test-case or method-level granularity, you need to pass parameters to the
140+
// test framework at the command line.
136141

137142
//// SNIPPET:RUNSINGLE
143+
// e.g. {utest-github-url}[uTest framework] used in this example lets you pass in a
144+
// selector to decide which individual test case to run via:
138145
/** Usage
139146

140147
> ./mill foo.test foo.FooMoreTests
141148
...foo.FooMoreTests...hello ...
142149

143-
*/
144-
145-
//// SNIPPET:END
146-
147-
/** Usage
148-
149150
> ./mill bar.test bar.BarTests.hello
150151
...bar.BarTests...hello ...
151152

152153
*/
153154

154-
// This command only runs the `hello` test case in the `bar.BarTests` test suite class.
155+
//// SNIPPET:END

libs/javalib/src/mill/javalib/TestModule.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ trait TestModule
162162
val (s, t) = args.splitAt(pos)
163163
(s, t.tail)
164164
}
165+
165166
Task.Command {
166167
testTask(Task.Anon { testArgs }, Task.Anon { selector })()
167168
}

0 commit comments

Comments
 (0)