无法使Robotium工作。它曾经,但现在总是失败并出现错误:
Running tests
Test running startedFinish
Empty test suite.
我的考试草稿:
public class MainActivityTest extends ActivityInstrumentationTestCase2 <MainActivity> {
private Solo solo;
public MainActivityTest() {
super(MainActivity.class);
}
@Override
protected void setUp() throws Exception {
super.setUp();
solo = new Solo(getInstrumentation(), getActivity());
}
@Override
protected void tearDown() throws Exception {
super.tearDown();
solo.finishOpenedActivities();
}
@Override
protected void runTest() throws Throwable {
super.runTest();
}
}
的build.gradle
defaultConfig {
applicationId "my.app"
testInstrumentationRunner "android.test.InstrumentationTestRunner"
}
的AndroidManifest.xml
<instrumentation
android:name="android.test.InstrumentationTestRunner"
android:targetPackage="my.app"/>
在Edit configurations
for instrumentation runner中我有android.test.InstrumentationTestRunner
。问题出在哪里?
答案 0 :(得分:0)
我已经想出空测试并且开始测试完成测试是我的运行测试无法调用测试方法,为此你必须在 MainActivity 类方法前加上测试MainActivity方法。 e.g
Class MAinActivity extends Activity{ //Class A
public void calculateSomething(){}
}
Class MAinActivityTest extends ActivityInstrumentationTestCase2 <MainActivity>{ //Class B - Test Class in your case MainActivityTest
@TestCalculate
public void testCalculateSomething(){
//Do your testing here
}
}
不要忘记调用主要Activity函数的顺序与TestClass中的相同。
了解更多信息,请检查 Why is the Android test runner reporting "Empty test suite"?