2016-07-13 14 views
6

Ich bin ein Anfänger zum Testen. Ich habe einen einfachen Testfall für die Login-Aktivität in Android Studio erstellt. Aber ich habe einen Fehler und ich konnte ihn nicht lösen. Hier ist mein Testcode. Hilfe wird sehr geschätzt.Fehler "Keine Tests gefunden", wenn Android Instrumententests ausgeführt werden

package com.example.hassidiczaddic.testinglist; 

import android.app.Application; 
import android.support.test.rule.ActivityTestRule; 
import android.support.test.runner.AndroidJUnit4; 
import android.test.ActivityInstrumentationTestCase2; 
import android.test.ApplicationTestCase; 
import android.test.suitebuilder.annotation.LargeTest; 

import org.junit.Before; 
import org.junit.Rule; 
import org.junit.Test; 
import org.junit.runner.RunWith; 

import static android.support.test.espresso.Espresso.onView; 
import static android.support.test.espresso.action.ViewActions.click; 
import static android.support.test.espresso.action.ViewActions.closeSoftKeyboard; 
import static android.support.test.espresso.action.ViewActions.typeText; 
import static android.support.test.espresso.assertion.ViewAssertions.matches; 
import static android.support.test.espresso.matcher.ViewMatchers.withId; 
import static android.support.test.espresso.matcher.ViewMatchers.withText; 

@RunWith(AndroidJUnit4.class) 
@LargeTest 
public class ApplicationTest { 

    public static final String STRING_TO_BE_TYPED = "Wolfmatrix"; 

    @Rule 
    public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule<>(MainActivity.class); 

    @Test 
    public void LoginActivity() { 
     onView(withId(R.id.etFName)) 
       .perform(typeText(STRING_TO_BE_TYPED), closeSoftKeyboard()); 
     onView(withId(R.id.etLName)) 
       .perform(typeText(STRING_TO_BE_TYPED), closeSoftKeyboard()); 
     onView(withId(R.id.btnSubmit)) 
      .perform(click()); 
     onView(withId(R.id.tvView)) 
      .check(matches(withText(STRING_TO_BE_TYPED))); 
    } 

} 

Das ist mein Fehler:

Running tests 

$ adb shell am instrument -w -r -e debug false -e class  
com.example.hassidiczaddic.testinglist.ApplicationTest 
com.example.hassidiczaddic.testinglist. 
test/android.test.InstrumentationTestRunner 
Client not ready yet..Test running started 
junit.framework.AssertionFailedError: No tests found in  
com.example.hassidiczaddic.testinglist.ApplicationTest 
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:190) 
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:175) 
at  
android.test.InstrumentationTestRunner.onStart 
(InstrumentationTestRunner.java:555) 
at android.app.Instrumentation$InstrumentationThread.run 
(Instrumentation.java:1619) 
Tests ran to completion. 

Hier ist meine gradle Datei:

apply plugin: 'com.android.application' 

android { 
    compileSdkVersion 23 
    buildToolsVersion "23.0.3" 

    defaultConfig { 
     applicationId "com.example.hassidiczaddic.testinglist" 
     minSdkVersion 16 
     targetSdkVersion 23 
     versionCode 1 
     versionName "1.0" 
    } 

    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro' 
     } 
    } 

    dependencies { 
     compile fileTree(dir: 'libs', include: ['*.jar']) 
     testCompile 'junit:junit:4.12' 
     compile 'com.android.support:appcompat-v7:23.0.1' 
     // App dependencies 
     compile 'com.android.support:support-annotations:23.0.1' 
     compile 'com.google.guava:guava:18.0' 
     androidTestCompile 'com.android.support:support-annotations:23.0.1' 
     androidTestCompile 'com.android.support.test:runner:0.4.1' 
     androidTestCompile 'com.android.support.test:rules:0.4.1' 
     androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1' 
    } 
} 
+0

Können Sie teilen Sie Ihre gradle Dateien? – josemigallas

+0

Ich habe es gerade oben bearbeitet und angefügt. Danke – Niroj

Antwort

13

Sie vergessen haben AndroidJUnitRunner als Standard-Prüfgeräten Läufer einzustellen.

https://developer.android.com/topic/libraries/testing-support-library/index.html

Um AndroidJUnitRunner als Standard-Prüfgeräten Läufer in Ihrem Gradle Projekt, geben Sie diese Abhängigkeit in Ihrer build.gradle-Datei festgelegt:

android { 
    defaultConfig { 
     testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 
    } 
} 
+0

ya ich bemerkte es ... Anyways Vielen Dank für Ihre Hilfe. – Niroj

+1

@Nirojthapa hat dies Ihr Problem gelöst? Wenn ja, bitte die Antwort als richtig markieren;) – josemigallas

+0

oh !! ich vergesse es :) – Niroj

Verwandte Themen