我在Android Studio 3.2.1和Android Studio 3.4上尝试过,如果我在gradle文件中启用Java 8并运行espresso测试,则会收到以下错误消息:java.lang.RuntimeExceptionCause: java.lang.RuntimeException经过多次试验,我发现从gradle文件中删除Java8支持可解决此问题。但是Java 8对于我的项目很重要。您有更好的解决方案吗?这是我的代码:import static androidx.test.espresso.action.ViewActions.click;import static androidx.test.espresso.assertion.ViewAssertions.matches;import static androidx.test.espresso.matcher.ViewMatchers.withId;import static androidx.test.espresso.matcher.ViewMatchers.withText;import androidx.test.espresso.Espresso;import androidx.test.ext.junit.runners.AndroidJUnit4;import androidx.test.filters.LargeTest;import androidx.test.rule.ActivityTestRule;import com.dubizzle.workshopsample.R;import org.junit.Rule;import org.junit.Test;import org.junit.runner.RunWith;@RunWith(AndroidJUnit4.class)@LargeTestpublic class MainActivityUiTest { @Rule public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule<>(MainActivity.class); @Test public void testShareButtonClickedUi() { Espresso.onView(withId(R.id.txtStatus)) .check(matches(withText("Hello World!"))); Espresso.onView(withId(R.id.btnShare)).perform(click()); Espresso.onView(withId(R.id.txtStatus)) .check(matches(withText("onShareButtonClicked"))); }}
添加回答
举报
0/150
提交
取消