Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parameterized Groovy JUnit test-cases in Eclipse

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

like image 752
Oliver Charlesworth Avatar asked Jul 15 '13 19:07

Oliver Charlesworth


1 Answers

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" }
}
like image 55
Ray Tayek Avatar answered Nov 08 '22 15:11

Ray Tayek