I have organised my junit tests using one inner class per method as described:
Here, in a haacked article (about nunit testing), and
Here, in this SO question
public class TestMyThing {
public static class TestMyThingMethodOne {
@Test
public void testMethodOneDoesACertainBehaviour() {
// terse, clear testing code goes here
}
@Test
public void testMethodOneHasSomeOtherDesiredBehaviour() {
// more inspiring testing code here
}
}
public static class TestMyThingMethodTwo {
... etc
}
}
However, when I try to run the junit tests for this, Eclipse asks me which of the inner class tests I want to run and I can only choose one. Is there a way I can specify that I want every test in every inner class for the TestMyThing class to run?
I asked my question on the Eclipse forum in this post and it turns out that it is possible for Eclipse to run all the inner classes. I quote the reply, which I've tried and can confirm that it works great (i.e. I can call all of the tests in my inner classes with one command):
JUnit 4 comes with a runner class called Enclosed, which does what you need.
Annotate the outer class with @RunWith(Enclosed.class) with Enclosed = import org.junit.experimental.runners.Enclosed;
Usually you would just create separate classes ( just pojos with default constructor ) instead of packing distinct unit tests into single class. As your inner classes are static, there is no real advantage in doing this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With