[英]JUnit4 - AssertionFailedError: No tests found
I'm using AndroidJUnitRunner with Espresso.我在 Espresso 中使用 AndroidJUnitRunner。
I wrote a simple test but always receive this exception.我写了一个简单的测试,但总是收到这个异常。 According to Stackoverflow answers, the problem is messing up the JUnit3 and JUnit4 but I have never used JUnit3 in my project.根据 Stackoverflow 的回答,问题是弄乱了 JUnit3 和 JUnit4,但我从未在我的项目中使用过 JUnit3。
junit.framework.AssertionFailedError: No tests found in com.walletsaver.app.test.espresso.SignUpPopupTest 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 ActivityTestRule<LoginActivity> mActivityRule =
new ActivityTestRule<>(LoginActivity.class);
@Test
public void checkSignUpPopup() throws Exception {
onView(withText("Sign Up")).perform(click());
}
}
I found the problem.我发现了问题。 It was missed code in build.gradle
in the main module.它在主模块中的build.gradle
中遗漏了代码。 If you have this problem I advise to start with adding this line:如果你有这个问题,我建议从添加这一行开始:
android {
...
defaultConfig {
...
testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
}
...
}
android {
defaultConfig {
testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
}
}
dependencies {
androidTestImplementation "androidx.test:runner:1.4.0"
androidTestImplementation "androidx.test.ext:junit:1.1.3"
}
@RunWith(AndroidJUnit4::class)
class SomeInstrumentedTest {}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.