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

Unified Diff: base/test/android/javatests/src/org/chromium/base/test/BaseTestResult.java

Issue 1387633002: Update instrumentation tests to use PreTestHooks for policies (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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: 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) {

Powered by Google App Engine
This is Rietveld 408576698