gpt4 book ai didi

Android espresso 错误未找到测试

转载 作者:行者123 更新时间:2023-11-29 01:37:12 25 4
gpt4 key购买 nike

我尝试使用 Espresso 测试框架来测试我的应用。

环境:

Android Studio RC1(来自金丝雀)最新的 Android Gradle 插件,0.14+

我按照这里的描述添加 ( https://code.google.com/p/android-test-kit/wiki/Espresso#Getting_Started )

dependencies {
//espresso - test framework

androidTestCompile files('libs/espresso-1.1.jar',
'libs/testrunner-1.1.jar',
'libs/testrunner-runtime-1.1.jar')

androidTestCompile 'com.google.guava:guava:14.0.1',
'com.squareup.dagger:dagger:1.1.0',
'org.hamcrest:hamcrest-core:1.1',
'org.hamcrest:hamcrest-integration:1.1',
'org.hamcrest:hamcrest-library:1.1'
}

packagingOptions {
exclude 'LICENSE.txt'
}

defaultConfig {
//espresso - test framework
testInstrumentationRunner "com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner"
}

我还创建了简单的测试:

public class StartActivityTest extends ActivityInstrumentationTestCase2<StartActivity> {
public StartActivityTest(Class<StartActivity> activityClass) {
super(activityClass);
}

@Override
public void setUp() throws Exception {
super.setUp();
// Espresso will not launch our activity for us, we must launch it via getActivity().
getActivity();
}

public void testStartVisibility() {
onView(withId(R.id.app_title))
.check(matches(isDisplayed()));

onView(withId(R.id.app_thumb))
.check(matches(isDisplayed()));

onView(withId(R.id.label))
.check(matches(isDisplayed())
);

onView(withId(R.id.label)).check(matches(withText("Hello Espresso!")));
}

}

但是我得到一个错误:

com.android.builder.testing.ConnectedDevice > hasTests[Nexus 5 - 5.0] FAILED 
No tests found.
:app:connectedAndroidTest FAILED

FAILURE: Build failed with an exception.

See  screenshot for detailes

最佳答案

好的,我知道了。

我必须使用如下默认构造函数:

public StartActivityTest() {
super(StartActivity.class);
}

那个固定的问题。

关于Android espresso 错误未找到测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27187008/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com