A coworker has recently introduced Spock unit testing into our team's project, and I'm having an annoying problem with its Eclipse integration: whenever we create a parametrized test and use the @Unroll annotation on it, the Eclipse JUnit view loses the association with the test class and shows the results under "Unrooted Tests."
For instance, the results for this test class:
package test
import spock.lang.Specification
import spock.lang.Unroll
class TestSpockTest extends Specification {
def "Not Unrolled Test"() {
when: "something"
then: "one equals one"
1 == 1
}
@Unroll
def "Unrolled Test #param"(Integer param) {
when: "something"
then: "a numer equals itself"
param == param
where:
param << [1, 2, 3]
}
}
Display this way:
How can I get the unrolled test cases (e.g. "Unrolled Test 1") to show up under "test.TestSockTest" like "Not Unrolled Test"? Is there some naming convention for my Spock tests that the Eclipse JUnit plugin will understand?
I'm using:
It's a well known problem that arises because Spock can't (via its JUnit facade) tell Eclipse upfront how many test methods will get run, and what their names will be. (In data-driven tests, both of these aspects are dynamic. What gets reported to Eclipse upfront is the same as when @Unroll
isn't used. Eclipse gets confused when correlating this with what gets reported during the test run.)
I can't think of a good way to solve this problem on Spock's side. I've considered approaches such as adding some ugly heuristics or executing tests twice when running inside Eclipse, but none of them were convincing. A more desirable solution would be to improve the Eclipse JUnit plugin to better handle this situation, which can also arise in many other JUnit compatible test frameworks.
If you can't live with the current output, here are some steps you could take:
@Unroll
. (It only affects reporting, not execution. One reason why it's opt-in is that some IDEs have problems with it.)