JUnit parameterized tests

Is there a way to run/debug an individual test within a JUnit4 parameterized test class? While the whole set runs nicely, the only way I have found to run or debug a particular test instance is to create another class with a simple test methopd which delegates to the original class and passes the required parameters.

Mark Thornton

P.S. The JUnit developers would be happy to help find an appropriate  way to support this.

4 comments
Comment actions Permalink

On 5/24/2010 10:48 PM, Mark Thornton wrote:

Is there a way to run/debug an individual test within a JUnit4 parameterized test class? While the whole set runs nicely, the only way I have found to run or debug a particular test instance is to create another class with a simple test methopd which delegates to the original class and passes the required parameters.

>

Mark Thornton

>

P.S. The JUnit developers would be happy to help find an appropriate  way to support this.


Meaning, run a particular test method on a subclass, where the test
method is actually defined only in the base class?

public abstract class BaseTest {

     public void testFizzle() {
       assertTrue(getFoo().fizzle());
     }

     protected abstract Foo getFoo();
}

public class MyFooTest extends BaseTest {
     protected Foo getFoo() {
         return new MyFoo();
     }
}


// Need way to run MyFooTest.testFizzle()


0
Comment actions Permalink

No a parameterised test looks like this


@RunWith(Parameterized.class)
public class TestConnections {
     @Parameterized.Parameters public static List<String[]> data() {
          return Arrays.asList(new String[][] {{"param1"}});
     }

     public TestConnection(String parameter) {
         // save parameter
     }

     @Test public void test1() {
     }

     @Test public void test2() {
     }
}

What I want to do is run test1 (say) with one of the sets of parameters. What I do now is create another class like this

public class Auxillary {
     @Test public void test1() {
          new TestConnections("param1").test1();
     }
}

This is all using JUnit 4.x

0
Comment actions Permalink

Hello Mark,

I think that it is possible to create test with chosen in editor parameter.
Could you please create a feature request in http://youtrack.jetbrains.net.

Thank you
-


Anna Kozlova
JetBrains Inc.
http://www.intellij.com
"Develop with pleasure!"

No a parameterised test looks like this

@RunWith(Parameterized.class)
public class TestConnections {
@Parameterized.Parameters public static List<String[]> data() {
return Arrays.asList(new String[][] {{"param1"}});
}
public TestConnection(String parameter) {
// save parameter
}
@Test public void test1() {
}
@Test public void test2() {
}
}
What I want to do is run test1 (say) with one of the sets of
parameters. What I do now is create another class like this

public class Auxillary {
@Test public void test1() {
new TestConnections("param1").test1();
}
}
This is all using JUnit 4.x

---
Original message URL:
http://www.jetbrains.net/devnet/message/5263845#5263845



0
Comment actions Permalink

What about using a conditional break point? JUnit would still run all variations of the test but at least you wouldn't have to step through them manually...

0

Please sign in to leave a comment.