RFR: CODETOOLS-7903267: Support executing a single test method in a JUnit class

Jonathan Gibbons jjg at openjdk.org
Fri Sep 9 22:49:16 UTC 2022


Please review a medium-sized patch to support new feature that provides a way to specify that only parts of a test should be executed.  For JUnit tests, this allows a single method in the test to be executed, but the underlying mechanism is more general than that and can be leveraged by any framework that supports running many test cases within an overall test.

The feature is enabled by using a new syntactic form on the command line, informally called _query syntax_: `path-to-test?string`. The syntax is based on URL syntax, but note that unlike URLs, the query component comes at the end, and not before any fragment component. In other words, the full syntax is `path#id?string`. Generally, this reflects the hierarchical structure:   a path to a file, a test description within the file, and a string to specify part of the test to be run.

In terms of implementation, the "heavy lifting" is done in `TestManager`, to track the _file, id, query_ tuple, as compared to the previous _file, id_.  New abstractions `TestSpec` and `GroupSpec` are introduced, to replace stylistic use of simple strings.

The underlying JT Harness does not know (or need to know) about query components and so is unchanged. But the back end `RegressionScript` used to execute each test _does_ need to know the query component, and so the information about which tests involve a query component is tunneled through the `RegressionParameters` in a side channel, embodied by a new resource in the object. In itself, the `RegressionScript` has little to do with the query component, it is simply passed down to the actions of the test in a new `test.query` property or `TESTQUERY` environment variable.

`JUnitRunner` is updated to check for the new `test.query` property: if set, it is used as the name of a test method to be run. Note: a JUnit exception will be thrown and the test will fail if the method is not found. The exception does contain enough useful information to diagnose the issue, but we may want to detect and report the issue in a more friendly form in a followup change.

Finally, new jtreg self-tests are added to exercise the new feature.

-------------

Commit messages:
 - CODETOOLS-7903267: Support executing a single test method in a JUnit class

Changes: https://git.openjdk.org/jtreg/pull/115/files
 Webrev: https://webrevs.openjdk.org/?repo=jtreg&pr=115&range=00
  Issue: https://bugs.openjdk.org/browse/CODETOOLS-7903267
  Stats: 916 lines in 15 files changed: 775 ins; 88 del; 53 mod
  Patch: https://git.openjdk.org/jtreg/pull/115.diff
  Fetch: git fetch https://git.openjdk.org/jtreg pull/115/head:pull/115

PR: https://git.openjdk.org/jtreg/pull/115


More information about the jtreg-dev mailing list