我无法从终端运行@smalltests。我已经创建了我的设置的例子,我想让你指出我做错了什么。
我使用自己的默认runner类,如下所示:
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);
}
}
我把这个跑步者放在我的梯度上:
android {
defaultConfig {
testInstrumentationRunner "com.MyApp.instrumentation.config.MyAppTestRunner"
}
testBuildType 'integrationTest'
}
我也在使用这些依赖关系:
androidTestCompile com.android.support.test:runner:0.5
androidTestCompile com.android.support.test:rules:0.5
然后我创建了一个简单的类,其中一个测试用例用@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
}
}
所以这是我的设置。根据我正在使用的androidjunitrunner文档,要使用小注解运行测试,我应该执行以下操作:
运行特定的测试大小,即用smalltest或mediumtest或largetest注解:adb shell am instrument-w-e size[small | medium | large]com.android.foo/android.support.test.runner.androidjunitrunner
所以我在终点站要做的是:
adb shell am instrument -w -e size small com.MyApp.debug1.test/com.MyApp.instrumentation.config.MyAppTestRunner
但找不到@smalltest,输出为:
时间:0.001
正常(0个测试)
此外,如果我从android studio启动测试类,则可以看到以下错误:
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)
如果我将@smalltest改为@test(import org.junit.test;),当然可以解决这个问题
我用错课了吗?
1条答案
按热度按时间0kjbasz61#
注解
@SmallTest
,@MediumTest
等android.support.test.filters
不要更换发动机@Test
注解。这个@Test
需要注解来通知junit相应的方法是一个测试用例(http://junit.org/junit4/javadoc/latest/org/junit/test.html).在您的情况下,这将起作用: