Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1059)

Unified Diff: testing/android/junit/java/src/org/chromium/testing/local/GtestListener.java

Issue 596303002: Revert of Revert of [Android] JUnit runner + gyp changes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@deps-changes
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: testing/android/junit/java/src/org/chromium/testing/local/GtestListener.java
diff --git a/testing/android/junit/java/src/org/chromium/testing/local/GtestListener.java b/testing/android/junit/java/src/org/chromium/testing/local/GtestListener.java
new file mode 100644
index 0000000000000000000000000000000000000000..122d1355c021c128143c1dd0921397626b49e6f7
--- /dev/null
+++ b/testing/android/junit/java/src/org/chromium/testing/local/GtestListener.java
@@ -0,0 +1,80 @@
+// 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;
+import java.util.Set;
+
+/** A JUnit RunListener that emulates GTest output to the extent that it can.
+ */
+public class GtestListener extends RunListener {
+
+ private Set<Description> mFailedTests;
+ private final GtestLogger mLogger;
+ private long mRunStartTimeMillis;
+ private long mTestStartTimeMillis;
+ private int mTestsPassed;
+ private boolean mCurrentTestPassed;
+
+ public GtestListener(GtestLogger logger) {
+ mLogger = logger;
+ }
+
+ /** Called before any tests run.
+ */
+ @Override
+ public void testRunStarted(Description d) throws Exception {
+ mLogger.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;
+ mLogger.testRunFinished(mTestsPassed, mFailedTests, elapsedTimeMillis);
+ }
+
+ /** Called when a test is about to start.
+ */
+ @Override
+ public void testStarted(Description d) throws Exception {
+ mCurrentTestPassed = true;
+ mLogger.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;
+ mLogger.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;
+ mLogger.testFailed(f);
+ }
+
+}
+

Powered by Google App Engine
This is Rietveld 408576698