我正在做一个意式浓缩咖啡测试用例,由于上述错误,我的测试用例无法完成。 Android Studio没有给我任何有意义的反馈。以下是我的活动测试用例和相应的日志。
@MediumTest
@RunWith(AndroidJUnit4.class)
public class MainActivityTest {
@Rule
public ActivityTestRule<MainActivity> mActivityTestRule = new ActivityTestRule<>(MainActivity.class);
Presenter mPresenter = new Presenter();
/**
* This provides our Espresso test necessary permissions through getInstrumentation
*/
@Before
public void grantPermission() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
getInstrumentation().getUiAutomation().executeShellCommand(
"pm grant " + getTargetContext().getPackageName()
+ " android.permission.CALL_PHONE");
}
}
@Test
void testPressure(){
onView(withId(R.id.b_get_pressure)).perform(click());
String pressure = String.valueOf(mPresenter.getPressure()[0]);
onView(withId(R.id.tv_pressure)).check(matches(withText(pressure)));
}
@Test
void testTemperature(){
onView(withId(R.id.b_get_temp)).perform(click());
String pressure = String.valueOf(mPresenter.getTemperature()[0]);
onView(withId(R.id.tv_pressure)).check(matches(withText(pressure)));
}
@Test
void testUnsubscribe(){
onView(withId(R.id.b_unsubscribe)).perform(click());
onView(withId(R.id.b_unsubscribe)).check(matches(withId(R.string.unsubscribed)));
}
java.lang.Exception: Method testPressure() should be public
at org.junit.runners.model.FrameworkMethod.validatePublicVoid(FrameworkMethod.java:96)
at org.junit.runners.model.FrameworkMethod.validatePublicVoidNoArg(FrameworkMethod.java:74)
at org.junit.runners.ParentRunner.validatePublicVoidNoArgMethods(ParentRunner.java:155)
at org.junit.runners.BlockJUnit4ClassRunner.validateTestMethods(BlockJUnit4ClassRunner.java:208)
at org.junit.runners.BlockJUnit4ClassRunner.validateInstanceMethods(BlockJUnit4ClassRunner.java:188)
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:39)
at android.support.test.runner.AndroidJUnit4.<init>(AndroidJUnit4.java:49)
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
at android.support.test.internal.runner.junit4.AndroidAnnotatedBuilder.buildAndroidRunner(AndroidAnnotatedBuilder.java:71)
at android.support.test.internal.runner.junit4.AndroidAnnotatedBuilder.runnerForClass(AndroidAnnotatedBuilder.java:48)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
at android.support.test.internal.runner.AndroidRunnerBuilder.runnerForClass(AndroidRunnerBuilder.java:153)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at android.support.test.internal.runner.TestLoader.doCreateRunner(TestLoader.java:73)
at android.support.test.internal.runner.TestLoader.getRunnersFor(TestLoader.java:104)
at android.support.test.internal.runner.TestRequestBuilder.build(TestRequestBuilder.java:789)
at android.support.test.runner.AndroidJUnitRunner.buildRequest(AndroidJUnitRunner.java:539)
at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:382)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2145)
我看不到要初始化的任何内容。但是android studio说初始化错误。有人可以指出我的问题吗?