7

I'm having trouble running a Parameterized Groovy JUnit test-case in Eclipse (see below for test code and environment details).

Symptoms

  • Right-clicking on the class in Package Explorer and doing Run As -> JUnit Test Case just brings up a dialog claiming "No JUnit tests found".
  • Right-clicking on the project and doing Run As -> JUnit Test Case runs all test-cases except the parameterized Groovy one.

Things I've tried

  1. Ensuring a "normal" Groovy JUnit test-case runs. This works.
  2. Ensuring a parameterized Java test-case runs. This works.
  3. Manually creating a JUnit run configuration for this test-case. This works.

So

So I have an inconvenient workaround (3). But this isn't scalable, as this test-case still won't be included when I run all test-cases in the project.

Any ideas how I can get Eclipse/Groovy plugin/JUnit to automatically recognise my test-case?


Test-case code
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.Parameterized
import org.junit.runners.Parameterized.Parameters

@RunWith(Parameterized)
public class TestParams {
    final int a

    public TestParams(int a) { this.a = a }

    @Parameters
    public static Collection<Object[]> data() {
        def cases = new Object[2][1]
        cases[0][0] = 3
        cases[1][0] = 4
        Arrays.asList(cases)
    }

    @Test public void test() { println "a = $a" }
}

Environment

  • Eclipse Juno Service Release 2 (OSX)
  • Groovy-Eclipse 2.8.0
  • JUnit 4.10.0

Oliver Charlesworth
  • 267,707
  • 33
  • 569
  • 680
  • Hmmm...I am running in Kepler with Groovy-Eclipse 2.8.0 and the 2.1.5 compiler. This is working for me. Do you have any errors in your error log? Does content assist/navigation work inside of your class? – Andrew Eisenberg Jul 19 '13 at 19:31
  • @AndrewEisenberg: Content-assist seems to work ok, and no errors reported (as I say, this runs fine with an explicit run configuration). I am yet to explore Kepler (the IDE crashes immediately on my OSX). However, my general experience of the Groovy-Eclipse plugin (so far) is that it's **extremely** temperamental and buggy, so maybe I'm just unlucky here! – Oliver Charlesworth Jul 19 '13 at 19:34

1 Answers1

1

this code works on my juno eclipse, junit 4.10 and groovy 2.0.6. i started with your code, but had to fool around with the imports as some of the annotations were red. i also had to add the .class to parameterized.

import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.Parameterized
import org.junit.runners.Parameterized.Parameters
@RunWith(Parameterized.class) public class TestParams {
    final int a

    public TestParams(int a) { this.a = a }

    @Parameters
    public static Collection<Object[]> data() {
        def cases = new Object[2][1]
        cases[0][0] = 3
        cases[1][0] = 4
        Arrays.asList(cases)
    }

    @Test public void test() { println "a = $a" }
}
Ray Tayek
  • 9,841
  • 8
  • 50
  • 90
  • Unfortunately that doesn't work for me either, although I haven't tried rolling back to Groovy-Eclipse 2.0.6 (I'll try that tomorrow...) So if you change `Parameterized.class` back to `Parameterized`, it no longer works for you? – Oliver Charlesworth Jul 19 '13 at 03:09
  • oop, if i remove the .class, it still works. sorry about the confusion. – Ray Tayek Jul 19 '13 at 04:51