How to run all my junit class tests at once

I organized junit tests using one inner class for each method, as described:

Here, in an exempted article (on 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 junit tests for this, Eclipse asks which of the internal class tests I want to run, and I can only choose one. Is there a way to indicate that I want every test in all inner classes to run for the TestMyThing class?

+4
source share
2 answers

I asked my question on the Eclipse forum in this post , and it turns out that Eclipse can run all inner classes. I quote the answer I tried and can confirm that it works fine (i.e. I can call all tests in my inner classes with a single command):

JUnit 4 comes with the runner Enclosed class, which does what you need.

Annotate an outer class using @RunWith (Enclosed.class) with Enclosed = import org.junit.experimental.runners.Enclosed;

+6
source

Usually you simply create separate classes (only pojos with a default constructor) instead of packing separate unit tests into one class. Since your inner classes are static, there is no real advantage to this.

+3
source

Source: https://habr.com/ru/post/1393939/


All Articles