How to run a group of suites in Junit?

Asked

Viewed 1,077 times

9

I have the following suites below:

@RunWith(Suite.class)
// this other matters
@Suite.SuiteClasses({
        TestC.class,
        TestB.class,
        TestA.class
})
public class MySuiteA {}

@RunWith(Suite.class)
// this other matters
@Suite.SuiteClasses({
        TestD.class,
        TestE.class,
        TestF.class
})
public class MySuiteB {}

How would I make a suite or test to run the MySuiteA and MySuiteB?

  • I thought that just by scoring as solved you already earned the points. [=

1 answer

8


Nothing stops you from creating a suite of suites:

@RunWith(Suite.class)
@SuiteClasses({ com.package1.MySuiteA.class,
                com.package2.MySuiteB.class })
public class RunAllTests {

}

Reference: Launch Suite classes using Another Suite class (in English)


On the other hand, the fact that you’re trying to group Suites shoots my Spider-sense. Do you really need suites of suites? What is your goal?

Maybe you are looking to divide your tests according to some criteria:

  • To categorize tests (e.g., fast and slow) and choose which ones you want to include / delete from a Suite from a look at the functionality of Categories (in English).
  • If you want to run tests as determined profile of Maven, the functionality of Categories goes very well with the functionality of profiles. For more information see the article Using Junit @Category and Maven profiles to get stable test suites (in English).

If you give more details about the problem you are trying to solve I will be happy to help you with further suggestions.

  • I had tested it like this before but the IDE did not start the tests. Now that I tested it again it was. I did not understand what happened but it worked. Thank you. [=

  • I really need suites to run tests for Easycriteria. With it I have several tests that have to be run for each JPA implementation. I created a suite for each implementation and wanted one that ran everything. [=

  • 1

    Got it. And good luck with your Project :). About running a suite for each JPA implementation, I still think this is a good example of categorization. It even helps if you have shared tests across multiple implementations. E.g.: @Category({Hibernate.class, EclipseLink.class, OpenJPA.class, DataNucleus.class})

  • About the IDE, if it is the Eclipse, I personally acquired some prejudices against his native support for Junit (I picked up the time of the Classpathsuite. Since you use Maven, enjoy the Surefire, Failsafe etc and forget about IDE :D.

  • Um... Interesting proposal. In the Hiberante.class class I could add @Beforeclass for example? I’m using the idea and it was catching. O.o Well, I ran the test on the nail and went. [=

  • uaiHebert. Yes, you can annotate both classes and methods with classifiers. Then in the Suite you choose which categories should be included ;). Take a look at the Categories link in my answer which will be clearer.

  • Blzma. Thank you. [=

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.