我正在使用AndroidJUnitRunner和Espresso.
我写了一个简单的测试但总是收到这个例外.根据Stackoverflow的回答,问题是弄乱JUnit3和JUnit4,但我从未在我的项目中使用过JUnit3.
junit.framework.AssertionFailedError:在com.walletsaver.app.test.espresso.SignUpPopupTest中找不到测试
package com.walletsaver.app.test.espresso; import android.support.test.rule.ActivityTestRule; import android.support.test.runner.AndroidJUnit4; import android.test.suitebuilder.annotation.SmallTest; import com.walletsaver.app.activity.LoginActivity; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import static android.support.test.espresso.Espresso.onView; import static android.support.test.espresso.action.ViewActions.click; import static android.support.test.espresso.matcher.ViewMatchers.withText; @RunWith(AndroidJUnit4.class) @SmallTest public class SignUpPopupTest { @Rule public ActivityTestRulemActivityRule = new ActivityTestRule<>(LoginActivity.class); @Test public void checkSignUpPopup() throws Exception { onView(withText("Sign Up")).perform(click()); } }
运行配置:
输出:
我发现了这个问题.它build.gradle
在主模块中丢失了代码.如果你有这个问题,我建议先添加这一行:
android { ... defaultConfig { ... testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner' } ... }