简体   繁体   English

JUnit4 - AssertionFailedError:未找到测试

[英]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());
    }
}

Run configuration:运行配置: 在此处输入图片说明

Output:输出: 在此处输入图片说明

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.

相关问题 junit.framework.AssertionFailedError:在Android Studio的UiAutomator中找不到测试 - junit.framework.AssertionFailedError: No tests found in UiAutomator in Android Studio 获取junit.framework.AssertionFailedError:使用Unit和Mockito时,[package]中没有找到任何测试 - Getting junit.framework.AssertionFailedError: No tests found in [package] when using Unit and Mockito Android JUnit4 Instrumentation测试上没有可运行的方法 - No runnable methods on Android JUnit4 Instrumentation Tests 带有JUnit4测试的Android Studio 1.0.2 - Android Studio 1.0.2 with JUnit4 Tests 误报:junit.framework.AssertionFailedError:找不到EditText - False positives: junit.framework.AssertionFailedError: EditText is not found 与Robotium进行junit测试时出现AssertionFailedError - AssertionFailedError on junit test with Robotium 如何使用非常相似的 JUnit4 测试避免代码重复 - How to avoid code duplication with very similar JUnit4 tests Android JUnit4Runner不运行不是以&#39;test&#39;开头的测试 - Android JUnit4 runner does not run tests not starting with 'test' Android Junit4 测试未显示在 CircleCI 测试摘要中 - Android Junit4 tests are not showing up in CircleCI Test Summary Android JUnit4测试 - Android JUnit4 testing
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM