NetBeans 6.7 Broke My Parameterized Tests

If you had some JUnit parameterized tests with code such as:

import java.util.Collection;
import junit.framework.TestCase;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

@RunWith(Parameterized.class)
public class MyParamTest extends TestCase {

    public MyParamTest(String s1, String s2) {
        // do something with s1 and s2
    }

    public static Collection getParams() {
        // return test parameters
    }

    public void testSomeStuff() {
        // testing testing testing
    }
}

You may have found when you upgraded to Netbeans 6.7 (with the improved JUnit test runner) that your tests suddenly started failing.

This is because any class extending TestCase is run as a regular JUnit test and so will fail if it’s actually a parameterized test. Just change the code to use the static import instead:

import java.util.Collection;
import static junit.framework.TestCase.*;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

@RunWith(Parameterized.class)
public class MyParamTest {

    public MyParamTest(String s1, String s2) {
        // do something with s1 and s2
    }

    public static Collection getParams() {
        // return test parameters
    }

    public void testSomeStuff() {
        // testing testing testing
    }
}

Bob’s yer mother’s brother.

Related posts:

  1. Writing reflective unit tests to improve code quality
  2. Testing Abstract Classes With Mockito and JUnit
  3. 5 Reasons Why NetBeans Rocks
  4. Automatic release packaging w/ version numbers for Netbeans Java Projects…
  5. Netbeans 7 + Git plugin on Windows Issues?

This entry was posted in General, Java, Software Engineering and tagged Java, junit, netbeans, testing. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>