Terry K.
Terry K.

Reputation: 63

How can I prevent duplicated executing tests about Suite in JUnit4?

We are using Java 8 and Junit version 4.13.2, and we want to bundle the following two tests into a TestSuite to test them.

@RunWith(SpringRunner.class)
@SpringBootTest
@Transactional
public class ATest {

  // Some tests..

}
@RunWith(SpringRunner.class)
@SpringBootTest
@Transactional
public class BTest {

  // Some tests..

}

This is TestSuite class.

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


@RunWith(Suite.class)
@Suite.SuiteClasses({ATest.class, BTest.class})
public class ABSuite {
}

There is no problem executing tests for the ABSuite class. However, when running "run all tests" in IntelliJ or running mvn clean test, all methods of both ATest and BTest classes as well as ABSuite are executed twice, resulting in duplicate execution of each test class.

'run all tests' button in intellij'

While adding <excludedGroups>com.sov.example.BTest,com.sov.example.BTest</excludedGroups> to the maven-surefire-plugin configuration in pom.xml works when running mvn clean test, I would like to seek advice on how to prevent duplicate execution of the test classes when running "run all tests" in the IDE. Thank you

Upvotes: 1

Views: 117

Answers (0)

Related Questions