Question

I would like to launch some Suite classes with JUnit 4, using another Suite class. I have the following test suite for one package:

package com.manuel.package1;

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

@RunWith(Suite.class)
@SuiteClasses({ TestCase1.class, TestCase2.class,
    TestCase3.class, TestCase4.class })
public class AllTests1 {

}

Then, I would like to run all the tests suite I have, using something similar to:

package com.manuel;

import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
import com.manuel.package1;
import com.manuel.package2;

@RunWith(Suite.class)
@SuiteClasses({AllTests1.class, AllTests2.class})
public class RunAllTests {

}

I would rather use Annotations (@RunWith(Suite.class),@SuiteClasses({})) than any other way if possible.

Right now I am using this approach:

package com.manuel.package1;

import junit.framework.Test;
import junit.framework.TestSuite;

public class AllTests extends TestSuite {

    public static Test suite() {
        TestSuite suite = new TestSuite("Test for com.manuel.package1");
        suite.addTestSuite(TestCase1.class);
        suite.addTestSuite(TestCase2.class);
        suite.addTestSuite(TestCase3.class);
        suite.addTestSuite(TestCase4.class);
        return suite;
    }
}

And for running the test suites:

package com.manuel;

import junit.framework.Test;
import junit.framework.TestSuite;

public class AllTests {

    public static Test suite() {

        TestSuite suite = new TestSuite("Run all the tests");
        suite.addTest(com.manuel.package1.AllTests.suite());
        suite.addTest(com.manuel.package2.AllTests.suite());
        return suite;
    }

}

Thanks you in advance.

Was it helpful?

Solution

I answered my own question, this is the approach I follow:

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

}

And then, in each AllTests.class

@RunWith(Suite.class)
@SuiteClasses({ TestCase1.class, TestCase2.class, TestCase3.class, TestCase4.class })
public class AllTests {

}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top