Index: testing/android/java/src/org/chromium/testing/local/GtestListener.java |
diff --git a/testing/android/java/src/org/chromium/testing/local/GtestListener.java b/testing/android/java/src/org/chromium/testing/local/GtestListener.java |
new file mode 100644 |
index 0000000000000000000000000000000000000000..8d62126548c896a217fbf70fbd257e0684039b67 |
--- /dev/null |
+++ b/testing/android/java/src/org/chromium/testing/local/GtestListener.java |
@@ -0,0 +1,78 @@ |
+// Copyright 2014 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.testing.local; |
+ |
+import org.junit.runner.Description; |
+import org.junit.runner.Result; |
+import org.junit.runner.notification.Failure; |
+import org.junit.runner.notification.RunListener; |
+ |
+import java.util.HashSet; |
+ |
+/** A JUnit RunListener that emulates GTest output to the extent that it can. |
+ */ |
+public class GtestListener extends RunListener { |
+ |
+ private HashSet<Description> mFailedTests; |
+ private long mRunStartTimeMillis; |
+ private long mTestStartTimeMillis; |
+ private int mTestsTotal; |
+ private int mTestsPassed; |
+ private boolean mCurrentTestPassed; |
+ |
+ /** Called before any tests run. |
+ */ |
+ @Override |
+ public void testRunStarted(Description d) throws Exception { |
+ GtestLogger.testRunStarted(d.testCount()); |
+ mRunStartTimeMillis = System.currentTimeMillis(); |
+ mTestsPassed = 0; |
+ mFailedTests = new HashSet<Description>(); |
+ mCurrentTestPassed = true; |
+ } |
+ |
+ /** Called after all tests run. |
+ */ |
+ @Override |
+ public void testRunFinished(Result r) throws Exception { |
+ long elapsedTimeMillis = System.currentTimeMillis() - mRunStartTimeMillis; |
+ GtestLogger.testRunFinished(mTestsPassed, mFailedTests, elapsedTimeMillis); |
+ } |
+ |
+ /** Called when a test is about to start. |
+ */ |
+ @Override |
+ public void testStarted(Description d) throws Exception { |
+ mCurrentTestPassed = true; |
+ GtestLogger.testStarted(d); |
+ mTestStartTimeMillis = System.currentTimeMillis(); |
+ } |
+ |
+ /** Called when a test has just finished. |
+ */ |
+ @Override |
+ public void testFinished(Description d) throws Exception { |
+ long testElapsedTimeMillis = System.currentTimeMillis() - mTestStartTimeMillis; |
+ GtestLogger.testFinished(d, mCurrentTestPassed, testElapsedTimeMillis); |
+ if (mCurrentTestPassed) { |
+ ++mTestsPassed; |
+ } else { |
+ mFailedTests.add(d); |
+ } |
+ } |
+ |
+ /** Called when a test fails. |
+ */ |
+ @Override |
+ public void testFailure(Failure f) throws Exception { |
+ mCurrentTestPassed = false; |
+ System.err.println(f.getDescription()); |
+ if (f.getException() != null) { |
+ f.getException().printStackTrace(); |
+ } |
+ } |
+ |
+} |
+ |