Je ne peux pas exécuter mes @SmallTests à partir du terminal. J'ai créé un exemple de mon installation et j'aimerais que vous indiquiez ce que je fais de mal.Comment exécuter l'instrumentation @SmallTests à partir du terminal?
J'utilise ma propre classe par défaut Runner qui ressemble à ce que:
public class MyAppTestRunner extends AndroidJUnitRunner { @Override public Application newApplication(ClassLoader cl, String className, Context context) throws InstantiationException, IllegalAccessException, ClassNotFoundException { return super.newApplication(cl, MyAppTestApplication.class.getName(), context); } }
J'ai mis ce coureur dans mon gradle:
android { defaultConfig { testInstrumentationRunner "com.MyApp.instrumentation.config.MyAppTestRunner" } testBuildType 'integrationTest' }
J'utilise aussi les dépendances:
androidTestCompile com.android.support.test:runner:0.5 androidTestCompile com.android.support.test:rules:0.5
Et puis j'ai créé la classe simple avec un cas de test annotée avec @SmallTest:
import android.content.Intent; import android.support.test.filters.SmallTest; import android.support.test.rule.ActivityTestRule; import android.support.test.runner.AndroidJUnit4; import com.MyApp.a.ui.activity.WelcomeActivity; import org.junit.Before; import org.junit.Rule; import org.junit.runner.RunWith; @RunWith(AndroidJUnit4.class) public class ExampleTestPackage { @Rule public ActivityTestRule<WelcomeActivity> activityRule = new ActivityTestRule<>( WelcomeActivity.class, true, false ); @Before public void before() { activityRule.launchActivity(new Intent()); } @SmallTest public void exampleTest() { // some test code } }
C'est donc ma configuration. Selon documentation of AndroidJUnitRunner que je me sers, pour exécuter mes tests avec petite annotation que je dois faire quelque chose comme ceci:
Running a specific test size i.e. annotated with SmallTest or MediumTest or LargeTest: adb shell am instrument -w -e size [small|medium|large] com.android.foo/android.support.test.runner.AndroidJUnitRunner
Alors ce que je fais dans le terminal est:
adb shell am instrument -w -e size small com.MyApp.debug1.test/com.MyApp.instrumentation.config.MyAppTestRunner
Mais mon @SmallTest n'est pas trouvé et la sortie est:
Time: 0.001
OK (0 tests)
en outre, si je commence ma classe de test à partir d'Android studio je peux voir cette erreur:
java.lang.Exception: No runnable methods
at org.junit.runners.BlockJUnit4ClassRunner.validateInstanceMethods(BlockJUnit4ClassRunner.java:191)
at org.junit.runners.BlockJUnit4ClassRunner.collectInitializationErrors(BlockJUnit4ClassRunner.java:128)
at org.junit.runners.ParentRunner.validate(ParentRunner.java:416)
at org.junit.runners.ParentRunner.<init>(ParentRunner.java:84)
at org.junit.runners.BlockJUnit4ClassRunner.<init>(BlockJUnit4ClassRunner.java:65)
at android.support.test.internal.runner.junit4.AndroidJUnit4ClassRunner.<init>(AndroidJUnit4ClassRunner.java:37)
at android.support.test.runner.AndroidJUnit4.<init>(AndroidJUnit4.java:36)
at java.lang.reflect.Constructor.newInstance(Native Method)
at android.support.test.internal.runner.junit4.AndroidAnnotatedBuilder.buildAndroidRunner(AndroidAnnotatedBuilder.java:83)
at android.support.test.internal.runner.junit4.AndroidAnnotatedBuilder.runnerForClass(AndroidAnnotatedBuilder.java:62)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
at org.junit.runner.Computer.getRunner(Computer.java:40)
at org.junit.runner.Computer$1.runnerForClass(Computer.java:31)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.runners.model.RunnerBuilder.runners(RunnerBuilder.java:101)
at org.junit.runners.model.RunnerBuilder.runners(RunnerBuilder.java:87)
at org.junit.runners.Suite.<init>(Suite.java:81)
at org.junit.runner.Computer.getSuite(Computer.java:28)
at android.support.test.internal.runner.TestRequestBuilder.classes(TestRequestBuilder.java:789)
at android.support.test.internal.runner.TestRequestBuilder.build(TestRequestBuilder.java:753)
at android.support.test.runner.AndroidJUnitRunner.buildRequest(AndroidJUnitRunner.java:354)
at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:260)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1879)
Ce qui bien sûr peut être fixé si je change @SmallTest à @Test (org.junit.Test importation;)
Suis-je utiliser des classes mal là-bas?