I have a library whose Junit 3 tests I'd like to reuse on Android. The problem is that these tests depend on files being present (test data).
For Android this means that some setup code needs to call getContext().getAssets() and dump the asset files to the sdcard, where they will be picked up by the tests.
The problem is: where do I put this setup code? I can't put it in the test's setup, as it inherits from TestCase (and anyway that would mean its no longer portable). I can't put it in the AllTests suite, as that inherits from TestSuite. Since its a Junit project there's no Activity whose onCreate I can hook.
The solution is to make a custom InstrumentationTestRunner. Override onCreate, where custom setup logic can be stored. For example:
public class InstrumentationTestRunner extends
android.test.InstrumentationTestRunner {
@Override
public void onCreate(Bundle arguments) {
setUpTests();
super.onCreate(arguments);
}
protected void setUpTests() {
// ....
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With