JUnit4 - AssertionFailedError: No tests found
JUnit4 - AssertionFailedError: No tests found
我在 Espresso 中使用 AndroidJUnit运行ner。
我写了一个简单的测试,但总是收到这个异常。根据 Whosebug 的回答,问题是搞乱了 JUnit3 和 JUnit4,但我从未在我的项目中使用过 JUnit3。
junit.framework.AssertionFailedError: No tests found in 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());
}
}
运行配置:
输出:
我发现了问题。
它在主模块的 build.gradle
中遗漏了代码。
如果您遇到此问题,我建议您先添加此行:
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 {}
我在 Espresso 中使用 AndroidJUnit运行ner。
我写了一个简单的测试,但总是收到这个异常。根据 Whosebug 的回答,问题是搞乱了 JUnit3 和 JUnit4,但我从未在我的项目中使用过 JUnit3。
junit.framework.AssertionFailedError: No tests found in 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());
}
}
运行配置:
输出:
我发现了问题。
它在主模块的 build.gradle
中遗漏了代码。
如果您遇到此问题,我建议您先添加此行:
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 {}