How To Call Testcase Class Inside Other Testcase Class?
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 proble
Solution 1:
You tests should live in a different project not with your Activities. Then the test runner, usually InstrumentationTestRunner, will be able to discover and run your test cases using instrospection.
Solution 2:
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.
publicabstractclassActivityTestCaseextendsTestCase {
publicabstractActivitygetInstance();
publicstaticClassspecializedTester(final String specialty) {
returnnewActivityTestCase() {
publicActivitygetInstance() {
returnnewActivity(specialty);
}
};
}
publicvoidtestChildActivities() {
Activity activity = getInstance();
for(Activity a : activity.children()) {
// "check ripeness", "bargain hunt", "check out", etcClass c = specializedTester(a.specialty);
suite.addTestSuite(c);
}
}
staticTestSuite suite;
publicstaticvoidmain(String[] args) {
suite = newTestSuite(ActivityTestCase.specializedTester("buy groceries"));
TestRunner.run(suite);
}
}
Post a Comment for "How To Call Testcase Class Inside Other Testcase Class?"