Blog About Contact

NetBeans 6.7 Broke My Parameterized Tests

Published Thu, 6 Aug 2009

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.


About the Author

Richard Nichols is an Australian software engineer with a passion for making things.

Follow him on twitter or subscribe by RSS or email.

You might also enjoy reading -


Discuss / Comment

No one has commented yet.

Add a comment

  • {{e.error}}

Thanks for your comment!/

Required.
Valid email address required.
Required.
Posting message, please wait...