Ho creato un semplice test in Android Studio. E 'appena stampa hello from test
e si confronta con 1
5
System.out.println nel test Android
package com.example.maks.firstapp.test;
import android.test.InstrumentationTestCase;
public class ExampleTest extends InstrumentationTestCase {
public void test() throws Exception {
System.out.println("hello from test");
final int expected = 1;
final int reality = 5;
assertEquals(expected, reality);
}
}
corro, ma non lo vedo da nessuna parte hello from test
.
L'output:
Running tests
Test running started
junit.framework.AssertionFailedError: expected:<1> but was:<5>
at com.example.maks.firstapp.test.ExampleTest.test(ExampleTest.java:15)
at java.lang.reflect.Method.invokeNative(Native Method)
at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:214)
at android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:199)
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:1661)
Finish
Dove System.out.println
realtà non stampare
Aggiornamento
ho cercato di usare Log.d("MyApp", "hello from test");
ma risultato è lo stesso.
Ho provato a cercare in diverse sotto-finestre da hello from test
ma non è stato trovato nulla.
Update 2
ho cambiato il codice da utilizzare e.Log
:
package com.example.maks.firstapp.test;
import android.test.InstrumentationTestCase;
import android.util.Log;
public class ExampleTest extends InstrumentationTestCase {
public void test() throws Exception {
Log.e("MyApp", "I am here");
final int expected = 1;
final int reality = 5;
assertEquals(expected, reality);
}
}
Screenshots:
test è fatto.
Ma logcat
è vuota.
Non ho mai fatto test di unità su Android prima (hey, bene!) Ma in Android Studio c'è una scheda chiamata Log o qualcosa del genere, e puoi usare il casella di ricerca per filtrare i registri. – gengkev
@gengkev Ho verificato il duplicato e ho provato 'Log.d' e ho provato a cercare con' ciao da test', ma non è stato d'aiuto. –
Secondo http://stackoverflow.com/q/5451614/ 'Log.d' dovrebbe funzionare ... – gengkev