2import android.util.Log;3import org.junit.runner.Description;4import org.junit.runner.Result;5import org.junit.runner.notification.Failure;6import org.junit.runner.notification.RunListener;7public class LogRunListener extends RunListener {8 @Override // org.junit.runner.notification.RunListener9 public void testRunStarted(Description description) throws Exception {10 Log.i("TestRunner", String.format("run started: %d tests", Integer.valueOf(description.testCount())));11 }12 @Override // org.junit.runner.notification.RunListener13 public void testRunFinished(Result result) throws Exception {14 Log.i("TestRunner", String.format("run finished: %d tests, %d failed, %d ignored", Integer.valueOf(result.getRunCount()), Integer.valueOf(result.getFailureCount()), Integer.valueOf(result.getIgnoreCount())));15 }16 @Override // org.junit.runner.notification.RunListener17 public void testStarted(Description description) throws Exception {18 String valueOf = String.valueOf(description.getDisplayName());19 Log.i("TestRunner", valueOf.length() != 0 ? "started: ".concat(valueOf) : new String("started: "));20 }21 @Override // org.junit.runner.notification.RunListener22 public void testFinished(Description description) throws Exception {23 String valueOf = String.valueOf(description.getDisplayName());24 Log.i("TestRunner", valueOf.length() != 0 ? "finished: ".concat(valueOf) : new String("finished: "));25 }26 @Override // org.junit.runner.notification.RunListener27 public void testFailure(Failure failure) throws Exception {28 String valueOf = String.valueOf(failure.getDescription().getDisplayName());29 Log.e("TestRunner", valueOf.length() != 0 ? "failed: ".concat(valueOf) : new String("failed: "));30 Log.e("TestRunner", "----- begin exception -----");31 Log.e("TestRunner", failure.getTrace());32 Log.e("TestRunner", "----- end exception -----");33 }34 @Override // org.junit.runner.notification.RunListener35 public void testAssumptionFailure(Failure failure) {36 String valueOf = String.valueOf(failure.getDescription().getDisplayName());37 Log.e("TestRunner", valueOf.length() != 0 ? "assumption failed: ".concat(valueOf) : new String("assumption failed: "));38 Log.e("TestRunner", "----- begin exception -----");39 Log.e("TestRunner", failure.getTrace());40 Log.e("TestRunner", "----- end exception -----");41 }42 @Override // org.junit.runner.notification.RunListener43 public void testIgnored(Description description) throws Exception {44 String valueOf = String.valueOf(description.getDisplayName());45 Log.i("TestRunner", valueOf.length() != 0 ? "ignored: ".concat(valueOf) : new String("ignored: "));46 }47}