0
votes

I use Eclipse Oxygen and JUnit 5. I have a class with a method and 3 test cases for the method that work fine. When I try to create a JUnit test suite to group all the cases by new/other/Java/JUnit/Junit test case in the window for test suite nothing appears in "Test classes to include in suite" despite that everything is in one packet and even set to public. I create the test suite and manually type in the classes I want to include in the test suit.

package testing;

import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;

@RunWith(Suite.class)
@SuiteClasses({oddNumberOfLettersPalindromeTest.class, 
evenNumberOfLettersPalindromeTest.class, notAPalindromeTest.class})
public class AllTests {
}

When I run the AllTest suite I get only 1/1 runs for the same AllTest suite class. All my JUnit tests have @Test as well

5

5 Answers

0
votes

Correct me if I wrong but do you want to add new classes every time foreach test? In that case you can use the @Before tag in JUnit. What it does is it generates a new class every time a @Test is hit.

private TestClass test;

@Before
public void setUp()
{
test = new TestClass();
//You can declare other classes right here
}
0
votes

It has to do with versions of JUnit or something, on my laptop it was JUnit 5 and eclipse oxygen, now I am on JUnit4 and eclipse Mars and everything is working fine. I just wanted to group few testcases in one suite

0
votes

It looks like your test suite is not importing the test cases you want to trigger. Also, apparently your test cases are not following the class naming pattern (starting with lower case and so on).

package testing;

import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
import OddNumberOfLettersPalindromeTest;
import EvenNumberOfLettersPalindromeTest;
import NotAPalindromeTest;

@RunWith(Suite.class)
@SuiteClasses({OddNumberOfLettersPalindromeTest.class, 
EvenNumberOfLettersPalindromeTest.class, NotAPalindromeTest.class})
public class AllTests {
}

I believe by doing this it has no reason to work.

-2
votes

Try changing the Junit version to Junit4 in build path -> libraries.