猿问

启用Java 8时,Android Studio Ui测试给出错误

我在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)

@LargeTest

public 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")));

  }

}


神不在的星期二
浏览 145回答 2
2回答
随时随地看视频慕课网APP

相关分类

Java
我要回答