JUnit4 - AssertionFailedError:未找到任何测试

时间:2015-12-22 17:00:50

标签: android testing junit junit4 android-espresso

我正在使用AndroidJUnitRunner和Espresso。

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

  

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

运行配置: enter image description here

输出: enter image description here

2 个答案:

答案 0 :(得分:99)

我发现了问题。 它在主模块的build.gradle中丢失了代码。 如果你有这个问题,我建议先添加这一行:

android {
    ...

    defaultConfig {
        ...

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

答案 1 :(得分:0)

╒═══════════╤═══════════════════════════╕
│"list_path"│"cost"                     │
╞═══════════╪═══════════════════════════╡
│[0,1]      │[0.0,50.0]                 │
├───────────┼───────────────────────────┤
│[0,2,4,3,1]│[0.0,50.0,90.0,120.0,170.0]│
└───────────┴───────────────────────────┘

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

dependencies {
    androidTestImplementation "androidx.test:runner:1.4.0"
    androidTestImplementation "androidx.test.ext:junit:1.1.3"
}