JUnit4 - AssertionFailedError: No tests found

…衆ロ難τιáo~ 提交于 2021-02-06 06:55:59

问题


I'm using AndroidJUnitRunner with Espresso.

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: 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());
    }
}

Run configuration:

Output:


回答1:


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'
    }
...
}


来源:https://stackoverflow.com/questions/34420896/junit4-assertionfailederror-no-tests-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!