Android Studio Espresso 空测试套件
Android Studio Espresso Empty Test Suite
当我 运行 我的测试方法使用 Espresso 时,它提示我选择一个模拟器,我选择了我现有的模拟器,我的应用程序已经启动。模拟器随后自动重启我的应用程序,然后显示测试套件为空。
我的 espresso 测试用例与我要测试的 activity 位于同一模块的 androidTest 文件夹中。我写了一个简单的 "isDisplayed()" 类型的测试,然后右键单击该方法并单击 运行。我查看了有关 Stack Overflow 和其他资源的其他问题,但我无法弄清楚是什么导致了这个问题。 logcat 什么都不显示,当我尝试将 Log.d("debug", "hello hello") 放入测试方法(如下所示)时,logcat 中什么也没有显示,当我尝试在测试方法中放置 System.out.println("hello") 时,也没有显示任何内容。似乎虽然我 运行 方法,但我的代码 none 是 运行!
下面是我的一些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
也许这会对其他人有所帮助(例如 Igor Ganapolsky)。
当您使用来自 Espresso 库的注释时,您必须将 testInstrumenatationRunner 添加到您的 gradle 文件中。缺少此行会出现相同的错误消息“Empty test suite”
defaultConfig {
applicationId "com.test.app"
minSdkVersion 16
targetSdkVersion 24
versionCode 1
versionName "1.0.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
当我 运行 我的测试方法使用 Espresso 时,它提示我选择一个模拟器,我选择了我现有的模拟器,我的应用程序已经启动。模拟器随后自动重启我的应用程序,然后显示测试套件为空。
我的 espresso 测试用例与我要测试的 activity 位于同一模块的 androidTest 文件夹中。我写了一个简单的 "isDisplayed()" 类型的测试,然后右键单击该方法并单击 运行。我查看了有关 Stack Overflow 和其他资源的其他问题,但我无法弄清楚是什么导致了这个问题。 logcat 什么都不显示,当我尝试将 Log.d("debug", "hello hello") 放入测试方法(如下所示)时,logcat 中什么也没有显示,当我尝试在测试方法中放置 System.out.println("hello") 时,也没有显示任何内容。似乎虽然我 运行 方法,但我的代码 none 是 运行!
下面是我的一些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
也许这会对其他人有所帮助(例如 Igor Ganapolsky)。
当您使用来自 Espresso 库的注释时,您必须将 testInstrumenatationRunner 添加到您的 gradle 文件中。缺少此行会出现相同的错误消息“Empty test suite”
defaultConfig {
applicationId "com.test.app"
minSdkVersion 16
targetSdkVersion 24
versionCode 1
versionName "1.0.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}