Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I avoid running junit tests twice in eclipse when using a TestSuite?

I need to do some per-suite initialisation (starting a web-server). It is working fine except that when I run all tests in my project in eclipse my tests run twice. My test suite looks a bit like this:

@RunWith(Suite.class)
@Suite.SuiteClasses({
   SubtestOne.class,
   SubtestTwo.class
})
public class TestSuite
{
   [...]
}

public class SubtestOne
{
   @Test public void testOne() { [...] }
}

public class SubtestTwo
{
   @Test public void testTwo() { [...] }
}

When I run all test in project in eclipse this causes the junit plugin to run the tests twice like this:

  • SubtestOne
  • SubtestTwo
  • TestSuite
    • SubtestOne
    • SubtestTwo

Is it possible to make "run all test in project" not run the sub-tests twice? I want my sub tests to be only ever run as part of the suite.

like image 659
lexicalscope Avatar asked Jun 07 '12 12:06

lexicalscope


People also ask

What is Testsuite in JUnit?

Test suite is used to bundle a few unit test cases and run them together. In JUnit, both @RunWith and @Suite annotations are used to run the suite tests. This chapter takes an example having two test classes, TestJunit1 & TestJunit2, that run together using Test Suite.


1 Answers

No, the test class will always be started directly and then through the "link" in the suite. This is as expected.

One workaround might to set in the run configuration to only run tests from the package which contains your suites. Open the run configuration and select Run all tests in the selected project, package or source folder then click Search... and select the package.

like image 142
Kai Avatar answered Sep 29 '22 18:09

Kai