Chromium Code Reviews| Index: testing/android/java/src/org/chromium/test/outstrumentation/reporter/ReporterListener.java |
| diff --git a/testing/android/java/src/org/chromium/test/outstrumentation/reporter/ReporterListener.java b/testing/android/java/src/org/chromium/test/outstrumentation/reporter/ReporterListener.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..22dd5b4dad28b394d7d627628df377cfe8572bbe |
| --- /dev/null |
| +++ b/testing/android/java/src/org/chromium/test/outstrumentation/reporter/ReporterListener.java |
| @@ -0,0 +1,80 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +package org.chromium.test.outstrumentation.reporter; |
| + |
| +import android.content.Context; |
| +import android.os.RemoteException; |
| +import android.util.Log; |
| + |
| +import junit.framework.AssertionFailedError; |
| +import junit.framework.Test; |
| +import junit.framework.TestCase; |
| +import junit.framework.TestListener; |
| + |
| +/** |
| + * A TestListener that reports when tests start, pass, or fail. |
| + */ |
| +public class ReporterListener implements TestListener { |
| + |
| + private static final String TAG = "ReporterListener"; |
| + |
| + private boolean mFailed; |
| + private final Reporter mReporter; |
| + |
| + public ReporterListener(Context context) { |
| + mReporter = new Reporter(context); |
| + } |
| + |
| + @Override |
| + public void addError(Test test, Throwable t) { |
| + Log.e(TAG, "Error while running " + test.toString(), t); |
| + mFailed = true; |
| + } |
| + |
| + public void addFailure(Test test, AssertionFailedError e) { |
|
Ted C
2015/04/06 17:43:54
javadoc
jbudorick
2015/04/07 00:54:39
Done.
|
| + Log.e(TAG, "Failure while running " + test.toString(), e); |
| + mFailed = true; |
| + } |
| + |
| + @Override |
| + public void startTest(Test test) { |
| + mFailed = false; |
| + if (test instanceof TestCase) { |
| + startTestCase((TestCase) test); |
| + } |
|
Ted C
2015/04/06 17:43:54
Could it ever not be a TestCase?
Should there be
jbudorick
2015/04/07 00:54:39
I don't think so, but that's based on Android, not
|
| + } |
| + |
| + private void startTestCase(TestCase testCase) { |
| + try { |
| + mReporter.testStarted(testCase.getClass().getName(), testCase.getName()); |
| + } catch (InterruptedException e) { |
| + Log.e(TAG, "Interrupted while reporting start of " + testCase.toString(), e); |
| + } catch (RemoteException e) { |
| + Log.e(TAG, "Remote error while reporting start of " + testCase.toString(), e); |
| + } |
| + } |
| + |
| + @Override |
| + public void endTest(Test test) { |
| + if (test instanceof TestCase) { |
| + endTestCase((TestCase) test); |
| + } |
| + } |
| + |
| + private void endTestCase(TestCase testCase) { |
| + try { |
| + if (mFailed) { |
| + mReporter.testFailed(testCase.getClass().getName(), testCase.getName()); |
| + } else { |
| + mReporter.testPassed(testCase.getClass().getName(), testCase.getName()); |
| + } |
| + } catch (InterruptedException e) { |
| + Log.e(TAG, "Interrupted while reporting start of " + testCase.toString(), e); |
| + } catch (RemoteException e) { |
| + Log.e(TAG, "Remote error while reporting start of " + testCase.toString(), e); |
| + } |
| + } |
| + |
| +} |