2

A similar question has already been asked here.

One (unaccepted) answer states:

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

Can someone explain what this actually means and whether or not it is possible to prevent the tests running twice.

When I run the tests from the command line using mvn test they only run once.

UPDATE

I have a test suite defined as follows:

@RunWith(Suite.class)
@SuiteClasses({ TestCase1.class, TestCase2.class })
public class MyTestSuite
{
}
Community
  • 1
  • 1
ksl
  • 4,519
  • 11
  • 65
  • 106
  • 1
    How are you running them? Right click -run as ( where, project level or test package level)? Do you have a test suite defined too - that too in same package level? – Sheetal Mohan Sharma Jan 11 '16 at 11:50
  • 1
    If you run the tests at the project level, then TestCase1 is executed and MyTestSuite is executed - which runs TestCase1 again. – James Jan 11 '16 at 12:29

3 Answers3

4

When you run tests in Eclipse on project level (or package level), Eclipse searches all project's source folders for JUnit classes (or selected package). These are all classes with @Test annotations and all classes with @RunWith (probably some more too). Then for all these classes it runs them as tests.

As a result of this behavior, if you have a suite class that references tests classes in the same project, these tests will run twice. If you had another suite that did the same, they would run three times and so on. To understand this behavior try running a suite that contains one test case twice, for instance:

@RunWith(Suite.class)
@SuiteClasses({ TestCase1.class, TestCase1.class })
public class TestSuite {}

Accepted strategy here is to define a suite or suites for a project an run them exclusively. Do not start tests on a project level but run selected suites only.

As far as Maven is concerned, I suspect that its default configuration only picks out suite class and omits test cases. Had it been configured differently, it would behave the same as Eclipse.

Michał Grzejszczak
  • 2,599
  • 1
  • 23
  • 28
0

Elipse tests 2 classes and give you 2 results. Maven tests 2 classes and give you one result with 2 sub results.

I think is somethink like this, but still most important thing is that result are positive! :) Regards!

amkz
  • 568
  • 3
  • 9
  • 31
0

Same as this question https://github.com/spring-projects/spring-boot/issues/13750

Just exclude individual test cases and include the suite test cases.

Mr.LiuDC
  • 109
  • 1
  • 3
  • 13
  • While this link may answer the question, link only answers are discouraged on Stack Overflow, you can improve this answer by taking vital parts of the link and putting it into your answer, this makes sure your answer is still an answer if the link gets changed or removed :) – WhatsThePoint Jul 11 '18 at 08:01