Chromium Code Reviews| Index: testing/android/java/src/org/chromium/testing/local/GtestComputer.java |
| diff --git a/testing/android/java/src/org/chromium/testing/local/GtestComputer.java b/testing/android/java/src/org/chromium/testing/local/GtestComputer.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..2133958617751cafe2fc5d22c1ddb753ae455549 |
| --- /dev/null |
| +++ b/testing/android/java/src/org/chromium/testing/local/GtestComputer.java |
| @@ -0,0 +1,71 @@ |
| +// 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. |
| + */ |
| +class GtestComputer extends Computer { |
| + |
| + /** |
| + * A wrapping Runner that logs the start and end of each test case. |
| + */ |
| + private static class GtestSuiteRunner extends Runner implements Filterable { |
| + private final Runner mRunner; |
| + |
| + GtestSuiteRunner(Runner contained) { |
| + super(); |
|
nyquist
2014/09/19 01:26:02
this call does nothing
jbudorick
2014/09/19 20:09:06
Done.
|
| + mRunner = contained; |
| + } |
| + |
| + public Description getDescription() { |
| + return mRunner.getDescription(); |
| + } |
| + |
| + public void run(RunNotifier notifier) { |
| + long startTimeMillis = System.currentTimeMillis(); |
| + GtestLogger.testCaseStarted(mRunner.getDescription(), |
| + mRunner.getDescription().testCount()); |
| + mRunner.run(notifier); |
| + GtestLogger.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); |
| + } |
| + |
| +} |
| + |