JUnit4-AssertionFailedError:未找到测试 [英] JUnit4 - AssertionFailedError: No tests found

查看:112
本文介绍了JUnit4-AssertionFailedError:未找到测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Espresso中使用AndroidJUnitRunner.

I'm using AndroidJUnitRunner with Espresso.

我编写了一个简单的测试,但始终收到此异常.根据Stackoverflow的答案,问题是使JUnit3和JUnit4混乱,但我从未在项目中使用过JUnit3.

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.

junit.framework.AssertionFailedError:com.walletsaver.app.test.espresso.SignUpPopupTest中找不到测试

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中缺少该代码. 如果您有此问题,建议从添加此行开始:

I found the problem. It was missed code in build.gradle in the main module. If you have this problem I advise to start with adding this line:

android {
    ...

    defaultConfig {
        ...

        testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
    }
...
}

这篇关于JUnit4-AssertionFailedError:未找到测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆