當我運行使用Espresso的測試方法時,它會提示我選擇一個模擬器,然後選擇我的現有模擬器,並啓動應用程序。仿真器隨後自動重新啓動我的應用程序,然後顯示測試套件是空的。Android Studio Espresso空測試套件
我的咖啡測試用例位於同一模塊,因爲我想測試活動的androidTest文件夾。我編寫了一個簡單的「isDisplayed()」類型的測試,並右鍵單擊該方法並單擊運行。我已經看了關於堆棧溢出和其他資源的其他問題,但我無法弄清楚是什麼導致了這個問題。 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()));
}
}
這是測試運行配置。
謝謝。 – Poptart
這並沒有解決我的問題。事實上,我已經擁有'@ Test'和'@ Before'。 –
@IgorGanapolsky'空測試套件'可以從字面上任何類型的問題 - 從gradle任務失敗到misconfigured @before方法。在這種情況下,這個問題很明顯。這可能與你的情況完全不同。 –