【问题标题】:Android unit testing, says I have no tests inside my class, although I have 1Android 单元测试,说我在课堂上没有测试,虽然我有 1
【发布时间】:2017-07-03 12:49:04
【问题描述】:

这就是我的 ApplicationTest 类的样子:

  /**
 * <a href="http://d.android.com/tools/testing/testing_android.html">Testing 
Fundamentals</a>
 */
@RunWith(AndroidJUnit4.class)
@LargeTest
public class ApplicationTest {
@Rule
public ActivityTestRule mActivityRule =
        new ActivityTestRule(VMBaseActivity.class,
                false /* Initial touch mode */, false /*  launch activity */) {

            @Override
            protected void afterActivityLaunched() {
                // Enable JavaScript.
                Log.i("","activity has been started");
            }
        };

@Test
public void enterPin() {
    // Type text and then press the button.
    onView(withId(R.id.button0)).perform(click());
    onView(withId(R.id.button0)).perform(click());
    onView(withId(R.id.button0)).perform(click());
    onView(withId(R.id.button0)).perform(click());
}
}

我的 build.gradle 中有这个

    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
})

但是当我运行时,我得到了这个错误:

 Client not ready yet..
 Started running tests

 junit.framework.AssertionFailedError: No tests found in com.vidyo.vidyomod.ApplicationTest
 at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:191)
 at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:176)
 at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:555)
 at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1893)

 Tests ran to completion.

为什么应用找不到我的测试?

【问题讨论】:

    标签: android unit-testing testing junit4 android-espresso


    【解决方案1】:

    将以下行添加到您的 app.gradle:

    默认配置 { testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" }

    【讨论】:

      【解决方案2】:

      我必须在我的 build.gradle 文件中添加这个:

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
      

      没有将跑步者设置为单元测试

      【讨论】:

        猜你喜欢
        • 2013-03-20
        • 1970-01-01
        • 2016-05-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-08-31
        • 2012-03-25
        • 2015-02-20
        相关资源
        最近更新 更多