Add junitSelectors instrumentation argument for batched method and invocation selection - #416
Open
GayatriNairAtBrowserstack wants to merge 1 commit into
Conversation
…vocation selection The 'class' instrumentation argument is read by both AndroidX's TestRequestBuilder and this runner. AndroidX compares its method part against reported test names, which for JUnit Jupiter are display names, so selecting several methods of one class in a single run filters out the whole class, and single invocations of parameterized tests cannot be selected at all. junitSelectors is read only by this runner: comma-separated com.Foo, com.Foo#method or com.Foo#method[n] (1-based invocation of a test template), including methods of @nested classes. Classes not mentioned run nothing, and the normal (non-legacy) name format is kept, so names match a full run. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The
classinstrumentation argument is read by two components at once: AndroidX'sTestRequestBuilderand this runner'sParsedSelectors. AndroidX applies its method filter to the reported test names, which for JUnit Jupiter are display names (display named failing,param(int) - [2] 2). So:-e class 'com.Foo#a,com.Foo#b', filters out the whole class, and 0 tests run. This holds whenever a selected method's display name differs from its Java name, including parameterized and repeated tests.am instrumentstart-up per method.This matters for tools that re-run failed tests: they want one instrumentation run for all failures, with names that match the original run.
Change
A new instrumentation argument,
junitSelectors, read only by this runner:com.Foo#methodselects a method (all overloads with that name)com.Foo#method[n]selects the n-th invocation (1-based, as in the display name) of a@TestTemplatemethod such as@ParameterizedTestor@RepeatedTest; for other methods the index is ignoredcom.Fooselects the classcom.Foo$Inner#testselects methods of@Nestedclasses through their enclosing class. AndroidX's class scan does not hand nested classes to the runner on its ownclass, and the normal (non-legacy) name format is kept, so reported names match a full runThe argument is parsed once in
JUnitFrameworkRunnerParams.create(), likeconfigurationParameters,environmentVariablesandsystemProperties.Tests
JUnitSelectorsTests(12 cases): several methods of one class, single invocations of parameterized, repeated and nested parameterized tests, nested methods and classes, dynamic tests through their factory, unknown classes, whitespace and duplicatestestFiveDebugUnitTestandtestSixDebugUnitTest: 109/109 pass@Nestedclasses andparam[2], executed exactly the selected tests, and only invocation 2 of the parameterized test. Reported names matched a full run in both the instrumentation output and logcat.The new tests are written with JUnit Jupiter, not added to
AndroidJUnitFrameworkTests, because that JUnit 4/Robolectric class is not picked up by the current unit test tasks (no vintage engine).🤖 Generated with Claude Code