Before submitting my test cases, I want to make sure they are running stably. Is there any way in Android Studio to run the same test case / class in loop for several times?
Annotate your test with @FlakyTest
. See http://developer.android.com/reference/android/test/FlakyTest.html
For instance
@FlakyTest(tolerance = 3)
public void myTest() {
// Test that sometimes fails for no good reason
}
Update: I see you're using Espresso. Then... no, this is not supported by android-test-kit
, unfortunately. But here's the feature request: https://code.google.com/p/android-test-kit/issues/detail?id=153
Use parameterized JUnit tests with several instances of empty parameter set:
@RunWith(Parameterized.class)
public class RepeatedTest {
private static final int NUM_REPEATS = 10;
@Parameterized.Parameters()
public static Collection<Object[]> data() {
Collection<Object[]> out = new ArrayList<>();
for (int i = 0; i < NUM_REPEATS; i++) {
out.add(new Object[0]);
}
return out;
}
@Test
public void unstableTest() {
// your test code here
}
}
A parameterized test class runs all its test methods once for every item in the method marked with the @Parameters
annotation. It is normally used to run a test with different initial values, but if there are no values to set up, the test is simply repeated as many times as you want.
The test will pass only if all the instances pass.
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