Burst 2.0 - Parameterized Android Tests #78
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.
I wanted to try out Burst 2.0 for Parameterized Android Tests.
Despite IDE support issues, the underlying library works 😄 .
Here are my observations:
It Works on Android! 🎉
https://github.com/google/TestParameterInjector also works, but this is special because it's not determining the tests to run via the JUnit Runner itself at runtime, but while the code is being compiled. This means we have deterministic test permutations generated and existing in the bytecode vs it being computed at test runner initialization time.
Because of this different method, computing all android tests to be run can be done via static analysis of the APK by tools like https://github.com/linkedin/dex-test-parser which computes a full list of methods from an APK. This also means that it will work in Firebase Test Lab and other sharding by method runners. Related Issue of TestParameterInjector -> google/TestParameterInjector#27 to allow that functionality.
Kotlin Compiler Plugin
The new test methods are never Kotlin Source Code, but go straight into the Kotlin Compiler's FIR model and then into the compiled Java Classes. While this is not unique to newer Kotlin Compiler Plugins, it's different from other KSP and KAPT annotation processing methods that end up generating source files that THEN get fed to the Kotlin Compiler. Because of that, you have to look at the compiled class files and don't have an intermediate source file to look at. This makes the compilation process MUCH faster by avoiding disk writes, avoiding different phases, and just doing everything within the compiler. The downside is knowing what's really going on under the hood.
Required Dependencies
It brings in
Kotlin 2.0.21
.Run Android Test IDE Issue
The option to run the test was there in the IDE even with the "red" highlighting. However, when the test was run it failed in the IDE. It DOES work when running the tests via the commandline with `./gradlew :app:connectedDebugAndroidTest", so it's definitely an IDE support issue.
IDE Highlighting Issues
This method of "code" (IR) generation inside the compiler doesn't seem to be something totally supported yet. I am using the latest stable version of Intellij IDEA and tried it with both K2 mode ON and OFF with the same result.