Index: base/test/android/javatests/src/org/chromium/base/test/BaseTestResult.java |
diff --git a/base/test/android/javatests/src/org/chromium/base/test/BaseTestResult.java b/base/test/android/javatests/src/org/chromium/base/test/BaseTestResult.java |
index 5802f40107de7c82922678ab460d21148d4338ee..59481379c1e74f04af1d4d58053c8bad2dbcaa2f 100644 |
--- a/base/test/android/javatests/src/org/chromium/base/test/BaseTestResult.java |
+++ b/base/test/android/javatests/src/org/chromium/base/test/BaseTestResult.java |
@@ -14,7 +14,6 @@ |
import junit.framework.TestResult; |
import org.chromium.base.Log; |
-import org.chromium.base.test.util.CommandLineFlags; |
import org.chromium.base.test.util.parameter.BaseParameter; |
import org.chromium.base.test.util.parameter.Parameter; |
import org.chromium.base.test.util.parameter.Parameterizable; |
@@ -22,6 +21,7 @@ |
import java.io.PrintWriter; |
import java.io.StringWriter; |
+import java.lang.reflect.Method; |
import java.util.ArrayList; |
import java.util.Arrays; |
import java.util.Iterator; |
@@ -40,12 +40,14 @@ |
private final Instrumentation mInstrumentation; |
private final List<SkipCheck> mSkipChecks; |
+ private final List<PreTestHook> mPreTestHooks; |
/** |
* Creates an instance of BaseTestResult. |
*/ |
public BaseTestResult(Instrumentation instrumentation) { |
mSkipChecks = new ArrayList<>(); |
+ mPreTestHooks = new ArrayList<>(); |
mInstrumentation = instrumentation; |
} |
@@ -64,6 +66,18 @@ public BaseTestResult(Instrumentation instrumentation) { |
} |
/** |
+ * An interface for classes that have some code to run before a test. Provides access to |
+ * the test method (and the annotations defined for it) and the instrumentation context. |
+ */ |
+ public interface PreTestHook { |
+ /** |
+ * @param targetContext the instrumentation context that will be used during the test. |
+ * @param testMethod the test method to be run. |
+ */ |
+ public void run(Context targetContext, Method testMethod); |
+ } |
+ |
+ /** |
* Adds a check for whether a test should run. |
* |
* @param skipCheck The check to add. |
@@ -72,6 +86,15 @@ public void addSkipCheck(SkipCheck skipCheck) { |
mSkipChecks.add(skipCheck); |
} |
+ /** |
+ * Adds hooks that will run before each test. |
+ * |
+ * @param preTestHook The hook to add. |
+ */ |
+ public void addPreTestHook(PreTestHook preTestHook) { |
+ mPreTestHooks.add(preTestHook); |
+ } |
+ |
protected boolean shouldSkip(TestCase test) { |
for (SkipCheck s : mSkipChecks) { |
if (s.shouldSkip(test)) return true; |
@@ -93,11 +116,14 @@ protected void run(TestCase test) { |
endTest(test); |
} else { |
try { |
- CommandLineFlags.setUp( |
- getTargetContext(), |
- test.getClass().getMethod(test.getName())); |
+ Method testMethod = test.getClass().getMethod(test.getName()); |
+ Context targetContext = getTargetContext(); |
+ |
+ for (PreTestHook hook : mPreTestHooks) { |
+ hook.run(targetContext, testMethod); |
+ } |
} catch (NoSuchMethodException e) { |
- Log.e(TAG, "Unable to set up CommandLineFlags", e); |
+ Log.e(TAG, "Unable to register annotation hooks", e); |
} |
if (test instanceof Parameterizable) { |