Can't run individual test methods from IntelliJ
jacobtabak opened this issue · 3 comments
For tests with method variations it seems like you can't run an individual test from IntelliJ, only all the tests in a class.
java.lang.Exception: No tests found matching Method multiple(com.squareup.burst.MethodTest) from org.junit.internal.requests.ClassRequest@2e26c3a1
at org.junit.internal.requests.FilterRequest.getRunner(FilterRequest.java:35)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:41)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:211)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:67)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Haven't really thought about if there's a fix or if it even matters.
Interesting. It seems when you run a single method, a Filter
is applied which matches Description
s with a unique ID of single(MethodTest)
. I tried changing describeChild
to have it generate these "bare" unique IDs (there's a separate display name which can still show the parameters). It sort of worked, but resulted in this funny hierarchy:
I'm now sure where this hierarchy is generated, but it seems having multiple tests share the same unique ID breaks an assumption somewhere.
I looked into Parameterized
a bit, since running individual Parameterized
tests somehow works.
Unfortunately it looks like IntelliJ made this work using a special SelectedParameterizedRunner which has direct access to the class and method name. They skip the normal test filtering code and do it in the runner's getChildren()
.
Haven't quite given up though. We can override ParentRunner
's filter
method so maybe we can add some special logic there instead of calling filter.shouldRun
.
I'm unable to run an individual test case from the latest Android Studio when I have @RunWith(BurstJUnit4::class)
on the test class. (Burst v1.2.0). When I try to run an individual test case, it runs all test cases in the class instead.
When I comment out that annotation (and whichever test(s) need Burst), then I can run individual test methods again.
This was definitely observed on Android Studio 4.0.2 and 4.1. I thought I'd seen this behavior prior to Android Studio 4.0 as well, but I hadn't considered the connection to Burst so I didn't test that at the time.
This is mainly significant when I'm trying to debug test runs after refactoring a class.