Skip to content

Commit 6f17d48

Browse files
authored
docs: clarify Maven test invocation for ScalaTest suites (#4238)
1 parent 47ec2a6 commit 6f17d48

1 file changed

Lines changed: 118 additions & 17 deletions

File tree

docs/source/contributor-guide/development.md

Lines changed: 118 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -230,33 +230,131 @@ cd native && cargo test
230230

231231
Alternatively, use `make test-rust` which handles the JVM compilation dependency automatically.
232232

233-
### Avoid Using `-pl` to Select Modules
233+
### Never Use `-pl` to Select Modules
234234

235-
When running Maven tests, avoid using `-pl spark` to select only the spark module. This can cause
236-
Maven to pick up the `common` module from your local Maven repository instead of using the current
237-
codebase, leading to inconsistent test results:
235+
Do not use `-pl spark` (or any other `-pl <module>`) when running Maven goals. With `-pl`, Maven
236+
does not rebuild sibling modules in the reactor and instead resolves them from your local Maven
237+
repository (`~/.m2/repository`). This leads to two failure modes:
238+
239+
- **Stale code.** Tests run against the last `mvn install`ed version of `common` (or
240+
`spark-shims`), not against your current edits. You can chase a "failing" test for hours that
241+
is actually green in your working tree.
242+
- **Cross-worktree corruption.** If you have multiple worktrees open and run `mvn install` in one
243+
while running `mvn test -pl spark` in another, the second worktree picks up the first
244+
worktree's artifacts from the shared `~/.m2/repository`. Builds and tests then mix code from
245+
different branches non-deterministically.
246+
247+
Always run Maven from the repo root without `-pl`. Maven's reactor will compile only what is
248+
needed:
238249

239250
```sh
240-
# Avoid this - may use stale common module from local repo
251+
# Wrong: resolves sibling modules from ~/.m2, breaks under concurrent worktrees
241252
./mvnw test -pl spark -Dsuites="..."
242253

243-
# Do this instead - builds and tests with current code
254+
# Right: reactor build, always uses current source
244255
./mvnw test -Dsuites="..."
245256
```
246257

247-
### Use `wildcardSuites` for Running Tests
258+
### Running a Specific ScalaTest Suite
259+
260+
To run a single suite (and only that suite), use `-Dsuites=` with the **fully qualified class name**
261+
and `-Dtest=none`:
262+
263+
```sh
264+
# Run exactly one suite
265+
./mvnw test -Dtest=none -Dsuites="org.apache.comet.CometArrayExpressionSuite"
266+
267+
# Run multiple suites (comma-separated, fully qualified)
268+
./mvnw test -Dtest=none -Dsuites="org.apache.comet.CometCastSuite,org.apache.comet.CometArrayExpressionSuite"
269+
270+
# Run only tests whose name contains "valid" inside one suite
271+
./mvnw test -Dtest=none -Dsuites="org.apache.comet.CometCastSuite valid"
272+
```
273+
274+
`-Dtest=none` tells the Surefire (JUnit) plugin to skip its tests; without it, Surefire still
275+
runs the JUnit `*Test.java` matchers in addition to your selected ScalaTest suite.
276+
277+
#### Pitfall: `-DwildcardSuites=""` runs everything
278+
279+
A common mistake is to combine `-Dsuites=...` with `-DwildcardSuites=""`:
280+
281+
```sh
282+
# WRONG: runs every suite in the project, takes ~1 hour
283+
./mvnw test -Dtest=none -Dsuites="org.apache.comet.CometArrayExpressionSuite" -DwildcardSuites=""
284+
```
285+
286+
`wildcardSuites` does substring matching, and the empty string is a substring of every suite
287+
name, so it expands to "run all suites" and overrides the narrower `-Dsuites=` selection. If you
288+
want to run a single suite, omit `-DwildcardSuites` entirely. If you want substring matching,
289+
pass a non-empty pattern:
290+
291+
```sh
292+
# Run every suite whose fully qualified name contains "CometCast"
293+
./mvnw test -Dtest=none -DwildcardSuites="CometCast"
294+
```
295+
296+
#### Pitfall: line breaks silently truncate the command
248297

249-
When running specific test suites, use `wildcardSuites` instead of `suites` for more flexible
250-
matching. The `wildcardSuites` parameter allows partial matching of suite names:
298+
A bare newline ends a shell command. If the command is split across lines without a trailing
299+
backslash, the shell only runs the first line and treats the rest as separate (failed)
300+
commands:
251301

252302
```sh
253-
# Run all suites containing "CometCast"
254-
./mvnw test -DwildcardSuites="CometCast"
303+
# WRONG: shell runs only the first line, which omits -Dsuites and runs every suite
304+
./mvnw test -Dtest=none
305+
-Dsuites="org.apache.comet.CometArrayExpressionSuite" -DfailIfNoTests=false
306+
```
307+
308+
The first line `./mvnw test -Dtest=none` runs every ScalaTest suite in the module (about 1800
309+
tests). The second line errors out trying to execute `-Dsuites=...` as a program, but by then
310+
the test run is already in progress. Symptom: you asked for one suite and ScalaTest reports
311+
"Expected test count is: 1797" starting at an alphabetically earlier suite.
255312

256-
# Run specific suite with filter
257-
./mvnw test -Dsuites="org.apache.comet.CometCastSuite valid"
313+
Either keep the command on one line, or use a trailing backslash on every continued line:
314+
315+
```sh
316+
./mvnw test -Dtest=none \
317+
-Dsuites="org.apache.comet.CometArrayExpressionSuite" \
318+
-DfailIfNoTests=false
258319
```
259320

321+
This is a common trap when copy-pasting commands from chat windows or terminals that wrap text
322+
without inserting the backslash.
323+
324+
#### Pitfall: a "successful" run does not mean your suite ran
325+
326+
Maven exits with status `0` whenever the build phases it executed completed without error, even
327+
when no ScalaTest suite matched your filter or a different suite ran than the one you intended.
328+
This is especially misleading for automated agents that key off the exit code: an empty or
329+
mistyped `-Dsuites=` value can produce a green run that tested nothing, or a wrong-but-matching
330+
suite name can run a much larger set than you wanted.
331+
332+
Always check the output, not just the exit code. ScalaTest prints a summary line near the end:
333+
334+
```text
335+
Run completed in 12 seconds, 345 milliseconds.
336+
Total number of tests run: 42
337+
Suites: completed 1, aborted 0
338+
Tests: succeeded 42, failed 0, canceled 0, ignored 0, pending 0
339+
All tests passed.
340+
```
341+
342+
Confirm both that the **suite count** matches what you asked for (typically `1`) and that the
343+
**test count** is in the expected range for that suite. A run that reports `Total number of
344+
tests run: 0` or one that reports thousands of tests when you asked for a single suite is a
345+
filter problem, not a successful run.
346+
347+
### Skip Scalastyle When Iterating
348+
349+
The `scalastyle:check` goal runs in every Maven test invocation and re-scans every Scala source
350+
file even when nothing relevant changed. When iterating on a single test, skip it:
351+
352+
```sh
353+
./mvnw test -Dtest=none -Dsuites="org.apache.comet.CometArrayExpressionSuite" -Dscalastyle.skip=true
354+
```
355+
356+
CI still enforces scalastyle, so this is purely a local iteration shortcut.
357+
260358
## Development Environment
261359

262360
Comet is a multi-language project with native code written in Rust and JVM code written in Java and Scala.
@@ -370,15 +468,18 @@ However if the tests is related to the native side. Please make sure to run `mak
370468

371469
### Running Tests from command line
372470

373-
It is possible to specify which ScalaTest suites you want to run from the CLI using the `suites`
374-
argument, for example if you only want to execute the test cases that contains _valid_
375-
in their name in `org.apache.comet.CometCastSuite` you can use
471+
Specify which ScalaTest suites to run with the `suites` argument and disable Surefire's JUnit
472+
discovery with `-Dtest=none`. For example, to run only the test cases containing _valid_ in
473+
their name from `org.apache.comet.CometCastSuite`:
376474

377475
```sh
378476
./mvnw test -Dtest=none -Dsuites="org.apache.comet.CometCastSuite valid"
379477
```
380478

381-
Other options for selecting specific suites are described in the [ScalaTest Maven Plugin documentation](https://www.scalatest.org/user_guide/using_the_scalatest_maven_plugin)
479+
See [Running a Specific ScalaTest Suite](#running-a-specific-scalatest-suite) above for the full
480+
list of common patterns and pitfalls (including why `-DwildcardSuites=""` silently runs every
481+
suite). Other options for selecting specific suites are described in the
482+
[ScalaTest Maven Plugin documentation](https://www.scalatest.org/user_guide/using_the_scalatest_maven_plugin).
382483

383484
## Plan Stability Testing
384485

0 commit comments

Comments
 (0)