¿Cómo llamar a la clase testcase dentro de otra clase testcase?

I have problem with creating JUnit Test Automation.

My project has many activities (some activities inside other activities). So I create testcase for each activity. But the problem how can i call a testcase inside other testcases (like activity inside other activities).

Can any one give me some idear?


preguntado el 10 de marzo de 12 a las 01:03

2 Respuestas

You tests should live in a different project not with your Activities. Then the test runner, usually InstrumentaciónTestRunner, will be able to discover and run your test cases using instrospection.

respondido 10 mar '12, 05:03

Disclaimer: this can get very, very messy. If you need one test case to spawn another test case, there's probably a better way of doing it.

JUnit operates on classes. If you want to create tests at runtime, you have to create classes at runtime. Here, the method specializedTester creates an anonymous subclass where getInstance() returns specialized Activity objects for testing.

public abstract class ActivityTestCase extends TestCase {

    public abstract Activity getInstance();

    public static Class specializedTester(final String specialty) {
        return new ActivityTestCase() {
            public Activity getInstance() {
                return new Activity(specialty);

    public void testChildActivities() {
        Activity activity = getInstance();
        for(Activity a : activity.children()) {
            // "check ripeness", "bargain hunt", "check out", etc
            Class c = specializedTester(a.specialty);

    static TestSuite suite;

    public static void main(String[] args) {
        suite = new TestSuite(ActivityTestCase.specializedTester("buy groceries"));

respondido 10 mar '12, 06:03

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.