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

Unified Diff: testing/android/junit/java/src/org/chromium/testing/local/GtestComputer.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/GtestComputer.java
diff --git a/testing/android/junit/java/src/org/chromium/testing/local/GtestComputer.java b/testing/android/junit/java/src/org/chromium/testing/local/GtestComputer.java
new file mode 100644
index 0000000000000000000000000000000000000000..3ef6d15c0c92ec141c19ac461cef81a7fa0e1a29
--- /dev/null
+++ b/testing/android/junit/java/src/org/chromium/testing/local/GtestComputer.java
@@ -0,0 +1,76 @@
+// 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.Computer;
+import org.junit.runner.Description;
+import org.junit.runner.Runner;
+import org.junit.runner.manipulation.Filter;
+import org.junit.runner.manipulation.Filterable;
+import org.junit.runner.manipulation.NoTestsRemainException;
+import org.junit.runner.notification.RunNotifier;
+import org.junit.runners.model.InitializationError;
+import org.junit.runners.model.RunnerBuilder;
+
+/**
+ * A Computer that logs the start and end of test cases googletest-style.
+ */
+public class GtestComputer extends Computer {
+
+ private final GtestLogger mLogger;
+
+ public GtestComputer(GtestLogger logger) {
+ mLogger = logger;
+ }
+
+ /**
+ * A wrapping Runner that logs the start and end of each test case.
+ */
+ private class GtestSuiteRunner extends Runner implements Filterable {
+ private final Runner mRunner;
+
+ public GtestSuiteRunner(Runner contained) {
+ mRunner = contained;
+ }
+
+ public Description getDescription() {
+ return mRunner.getDescription();
+ }
+
+ public void run(RunNotifier notifier) {
+ long startTimeMillis = System.currentTimeMillis();
+ mLogger.testCaseStarted(mRunner.getDescription(),
+ mRunner.getDescription().testCount());
+ mRunner.run(notifier);
+ mLogger.testCaseFinished(mRunner.getDescription(),
+ mRunner.getDescription().testCount(),
+ System.currentTimeMillis() - startTimeMillis);
+ }
+
+ public void filter(Filter filter) throws NoTestsRemainException {
+ if (mRunner instanceof Filterable) {
+ ((Filterable)mRunner).filter(filter);
+ }
+ }
+ }
+
+ /**
+ * Returns a suite of unit tests with each class runner wrapped by a
+ * GtestSuiteRunner.
+ */
+ @Override
+ public Runner getSuite(final RunnerBuilder builder, Class<?>[] classes)
+ throws InitializationError {
+ return super.getSuite(
+ new RunnerBuilder() {
+ @Override
+ public Runner runnerForClass(Class<?> testClass) throws Throwable {
+ return new GtestSuiteRunner(builder.runnerForClass(testClass));
+ }
+ }, classes);
+ }
+
+}
+
« no previous file with comments | « build/host_prebuilt_jar.gypi ('k') | testing/android/junit/java/src/org/chromium/testing/local/GtestFilter.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698