5

Sto provando a scrivere un test di strumentazione per il mio MainActivity. Ho seguito le risposte date here. Ancora Android Studio non riesce a trovare alcun test. Ho la classe ApplicationTest.java nella cartella androidTest. Ecco i contenuti della classe:Nessun errore ancora Android Studio dice "nessun test è stato trovato"

package com.example.monicamarcus.mymusicplayer 

import android.app.Activity; 
import android.test.ActivityInstrumentationTestCase2; 
import com.example.monicamarcus.mymusicplayer.MainActivity; 

public class ApplicationTest extends ActivityInstrumentationTestCase2<MainActivity> { 
    public ApplicationTest() { 
     super(MainActivity.class); 
    } 

    public void testNextTrackButton() throws Exception { 
     Activity activity = getActivity(); 

     Button nextButton = (Button) activity.findViewById(R.id.nextTrackBt); 
     activity.runOnUiThread(new Runnable() { 
      @Override 
      public void run() { 
       nextButton.performClick(); 
       assertTrue(currentPosition < songList.size()); 
      }}); 
     activity.finish(); 
    } 
} 

Cosa c'è di sbagliato in questa classe di test? O con i test? Non ho alcun errore, semplicemente non trova alcun test da eseguire. Dopo ho eseguito l'ApplicationTest l'uscita si conclude con le seguenti righe:

Running tests 
Test running startedFinish 
Empty test suite. 

Ecco il file build.gradle per l'applicazione:

apply plugin: 'com.android.application' 

android { 
    compileSdkVersion 23 
    buildToolsVersion "23.0.2" 

    defaultConfig { 
     applicationId "com.example.monicamarcus.mymusicplayer" 
     minSdkVersion 16 
     targetSdkVersion 23 
     versionCode 1 
     versionName "1.0" 
     testApplicationId "app.src.androidTest.java.com.example.monicamarcus.mymusicplayer" 
     testInstrumentationRunner "android.test.InstrumentationTestRunner" 
    } 
    buildTypes { 
     debug { 
      minifyEnabled false 
     } 
     release { 
      minifyEnabled true 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 
} 

android { 
    useLibrary 'org.apache.http.legacy' 
} 

android { 

    sourceSets { 

     androidTest { 
      java.srcDirs = ['androidTest/java'] 
     } 

    } 
} 

dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    testCompile 'junit:junit:4.12' 
    compile 'com.android.support:appcompat-v7:23.1.1' 
    androidTestCompile 'junit:junit:4.12' 
} 

ecco l'output del test:

Testing started at 1:56 PM ... 
Target device: gt_i8190n-4790068ee9a750c6 
Installing APK: /Users/monicamarcus/AndroidStudioProjects/MyMusicPlayer/app/build/outputs/apk/app-debug.apk 
Uploading file to: /data/local/tmp/com.example.monicamarcus.mymusicplayer 
Installing com.example.monicamarcus.mymusicplayer 
DEVICE SHELL COMMAND: pm install -r "/data/local/tmp/com.example.monicamarcus.mymusicplayer" 
pkg: /data/local/tmp/com.example.monicamarcus.mymusicplayer 
Success 


Installing APK: /Users/monicamarcus/AndroidStudioProjects/MyMusicPlayer/app/build/outputs/apk/app-debug-androidTest-unaligned.apk 
Uploading file to: /data/local/tmp/app.src.androidTest.java.com.example.monicamarcus.mymusicplayer 
Installing app.src.androidTest.java.com.example.monicamarcus.mymusicplayer 
DEVICE SHELL COMMAND: pm install -r "/data/local/tmp/app.src.androidTest.java.com.example.monicamarcus.mymusicplayer" 
pkg: /data/local/tmp/app.src.androidTest.java.com.example.monicamarcus.mymusicplayer 
Success 


Running tests 
Test running startedFinish 
Empty test suite. 

Dopo aver apportato alcune modifiche (posso pubblicarle se qualcuno è interessato) il risultato dell'esecuzione della classe di test della strumentazione è stato letto come segue: "Esecuzione di test. Nessun risultato del test. suite di test vuoto." Nessuno ha esperienza con questo tipo di test?

+0

Hai provato usando '@ Test' intead di '@ UiThreadTest'? –

+0

@OfficerBacon Sì, ho provato ma succede la stessa cosa. – Monica

+0

Ho cambiato il codice. vedi la modifica nella domanda. Qualsiasi aiuto sarebbe apprezzato molto. – Monica

risposta

2

In build.gradle, testApplicationId sembra molto strano. Vorrei rimuovere questo e testInstrumentationRunner. I valori di default dovrebbero andare bene. In particolare, se non si specifica testApplicationId, si verrà creato aggiungendo ".test" al vostro applicationId.

+0

Sì, ho letto da qualche parte che dovrei specificare questi nel file build.gradle. Tuttavia, ho rimosso quelle due linee, ma ottengo lo stesso risultato: Empty test suite. Grazie per aver tentato di aiutare. – Monica

+4

Sei riuscito a trovare una soluzione? Sto affrontando lo stesso problema e non riesco a risolverlo. – JFreeman

+0

Qualche soluzione a questo? Di fronte allo stesso problema. –

-1

Ho appena creato un nuovo progetto in studio Android 2.2.2, ha fatto un test di Android sicuro ha fatto un cC Gradle, ed ha ottenuto l'uscita in basso.

si può vedere il test ha esito negativo su ciascun dispositivo nella parte inferiore dell'uscita

questo question può essere correlato.

i rapporti sono in So35426990/app/build/rapporti/androidTests/collegato/index.html

d: \ AndroidStudioProjects \ So35426990> CC Gradle

Incremental java compilation is an incubating feature. 
The TaskInputs.source(Object) method has been deprecated and is scheduled to be 
removed in Gradle 4.0. Please use TaskInputs.file(Object).skipWhenEmpty() instea 
d. 
:app:preBuild UP-TO-DATE 
:app:preDebugBuild UP-TO-DATE 
:app:checkDebugManifest 
:app:preReleaseBuild UP-TO-DATE 
:app:prepareComAndroidSupportAnimatedVectorDrawable2421Library UP-TO-DATE 
:app:prepareComAndroidSupportAppcompatV72421Library UP-TO-DATE 
:app:prepareComAndroidSupportDesign2421Library UP-TO-DATE 
:app:prepareComAndroidSupportRecyclerviewV72421Library UP-TO-DATE 
:app:prepareComAndroidSupportSupportCompat2421Library UP-TO-DATE 
:app:prepareComAndroidSupportSupportCoreUi2421Library UP-TO-DATE 
:app:prepareComAndroidSupportSupportCoreUtils2421Library UP-TO-DATE 
:app:prepareComAndroidSupportSupportFragment2421Library UP-TO-DATE 
:app:prepareComAndroidSupportSupportMediaCompat2421Library UP-TO-DATE 
:app:prepareComAndroidSupportSupportV42421Library UP-TO-DATE 
:app:prepareComAndroidSupportSupportVectorDrawable2421Library UP-TO-DATE 
:app:prepareDebugDependencies 
:app:compileDebugAidl UP-TO-DATE 
:app:compileDebugRenderscript UP-TO-DATE 
:app:generateDebugBuildConfig UP-TO-DATE 
:app:generateDebugResValues UP-TO-DATE 
:app:generateDebugResources UP-TO-DATE 
:app:mergeDebugResources 
:app:processDebugManifest 
:app:processDebugResources UP-TO-DATE 
:app:generateDebugSources UP-TO-DATE 
:app:incrementalDebugJavaCompilationSafeguard UP-TO-DATE 
:app:compileDebugJavaWithJavac UP-TO-DATE 
:app:compileDebugNdk UP-TO-DATE 
:app:compileDebugSources UP-TO-DATE 
:app:mergeDebugShaders UP-TO-DATE 
:app:compileDebugShaders UP-TO-DATE 
:app:generateDebugAssets UP-TO-DATE 
:app:mergeDebugAssets UP-TO-DATE 
:app:transformClassesWithDexForDebug UP-TO-DATE 
:app:mergeDebugJniLibFolders UP-TO-DATE 
:app:transformNative_libsWithMergeJniLibsForDebug UP-TO-DATE 
:app:processDebugJavaRes UP-TO-DATE 
:app:transformResourcesWithMergeJavaResForDebug UP-TO-DATE 
:app:validateSigningDebug 
:app:packageDebug UP-TO-DATE 
:app:assembleDebug UP-TO-DATE 
:app:preDebugAndroidTestBuild UP-TO-DATE 
:app:prepareComAndroidSupportTestEspressoEspressoCore222Library UP-TO-DATE 
:app:prepareComAndroidSupportTestEspressoEspressoIdlingResource222Library UP-TO- 
DATE 
:app:prepareComAndroidSupportTestExposedInstrumentationApiPublish05Library UP-TO 
-DATE 
:app:prepareComAndroidSupportTestRules05Library UP-TO-DATE 
:app:prepareComAndroidSupportTestRunner05Library UP-TO-DATE 
:app:prepareDebugAndroidTestDependencies 
:app:compileDebugAndroidTestAidl UP-TO-DATE 
:app:processDebugAndroidTestManifest UP-TO-DATE 
:app:compileDebugAndroidTestRenderscript UP-TO-DATE 
:app:generateDebugAndroidTestBuildConfig UP-TO-DATE 
:app:generateDebugAndroidTestResValues UP-TO-DATE 
:app:generateDebugAndroidTestResources UP-TO-DATE 
:app:mergeDebugAndroidTestResources 
:app:processDebugAndroidTestResources UP-TO-DATE 
:app:generateDebugAndroidTestSources UP-TO-DATE 
:app:incrementalDebugAndroidTestJavaCompilationSafeguard UP-TO-DATE 
:app:compileDebugAndroidTestJavaWithJavac 
:app:compileDebugAndroidTestNdk UP-TO-DATE 
:app:compileDebugAndroidTestSources 
:app:mergeDebugAndroidTestShaders UP-TO-DATE 
:app:compileDebugAndroidTestShaders UP-TO-DATE 
:app:generateDebugAndroidTestAssets UP-TO-DATE 
:app:mergeDebugAndroidTestAssets UP-TO-DATE 
:app:transformClassesWithDexForDebugAndroidTest 
:app:mergeDebugAndroidTestJniLibFolders UP-TO-DATE 
:app:transformNative_libsWithMergeJniLibsForDebugAndroidTest UP-TO-DATE 
:app:processDebugAndroidTestJavaRes UP-TO-DATE 
:app:transformResourcesWithMergeJavaResForDebugAndroidTest UP-TO-DATE 
:app:validateSigningDebugAndroidTest 
:app:packageDebugAndroidTest 
:app:assembleDebugAndroidTest 
:app:connectedDebugAndroidTest 

acme.so35426990.ExampleInstrumentedTest > useAppContext[KFFOWI - 5.1] FAILED 
     java.lang.AssertionError: failing 
     at org.junit.Assert.fail(Assert.java:88) 

acme.so35426990.ExampleInstrumentedTest > useAppContext[KFFOWI - 5.1.1] FAILED 
     java.lang.AssertionError: failing 
     at org.junit.Assert.fail(Assert.java:88) 

acme.so35426990.ExampleInstrumentedTest > useAppContext[Nexus 7 - 5.1.1] FAILED 

     java.lang.AssertionError: failing 
     at org.junit.Assert.fail(Assert.java:88) 
                :app:connectedDebugAndroidTes 
t FAILEDng 96% > :app:connectedDebugAndroidTest 

FAILURE: Build failed with an exception. 

* What went wrong: 
Execution failed for task ':app:connectedDebugAndroidTest'. 
> There were failing tests. See the report at: file:///D:/AndroidStudioProjects/ 
So35426990/app/build/reports/androidTests/connected/index.html 

* Try: 
Run with --stacktrace option to get the stack trace. Run with --info or --debug 
option to get more log output. 

BUILD FAILED 

Total time: 35.227 secs 

d:\AndroidStudioProjects\So35426990> 
Problemi correlati