当我运行使用 Espresso 的测试方法时,它会提示我选择一个模拟器,然后我选择我现有的模拟器并启动我的应用程序。模拟器随后自动重启我的应用程序,然后显示测试套件为空。
我的 espresso 测试用例位于与我要测试的 Activity 相同的模块的 androidTest 文件夹中。我编写了一个简单的“isDisplayed()”类型的测试并右键单击该方法并单击运行。我查看了有关 Stack Overflow 和其他资源的其他问题,但我无法弄清楚是什么导致了这个问题。 logcat 什么都不显示,当我尝试将 Log.d("debug", "hello hello") 放入测试方法(如下所示)时,logcat 中什么也没有显示,当我尝试放置 System.out 时也没有任何显示.println("hello") 在测试方法中。似乎虽然我运行了该方法,但我的代码都没有运行!
下面是我的一些build.grade。
apply plugin: 'com.android.application'
android {
compileSdkVersion 17
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "x"
minSdkVersion 17
targetSdkVersion 17
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'LICENSE.txt'
}
}
configurations.all {
resolutionStrategy.force 'com.android.support:support-annotations:22.2.0'
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile 'com.android.support.test:rules:0.3'
androidTestCompile 'com.android.support.test:runner:0.3'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2'
}
这是我要运行的测试用例。
@RunWith(AndroidJUnit4.class)
public class EspressoTest1 extends ActivityInstrumentationTestCase2<P1>{
private P1 mActivity;
public EspressoTest1() {
super(P1.class);
}
public void setUp() throws Exception {
super.setUp();
injectInstrumentation(InstrumentationRegistry.getInstrumentation());
mActivity = getActivity();
}
public void Happy_test() {
onView(withId(R.id.Btn)).check(matches(isDisplayed()));
}
}
这是测试运行配置。
最佳答案
您的测试缺少 @Test
注释。因此,由于您的设置方法丢失了 @Before
关于Android Studio Espresso 空测试套件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31123017/