Commit bc7859de authored by Yoland Yan's avatar Yoland Yan Committed by Commit Bot

Initialize CommandLine for JUnit4 Tests

In JUnit3, CommandLine is initialized before a test run, we should do
the same to avoid test flakiness.

Bug: 640116
Change-Id: If9ac3945680060125cfc86b63cf79a91e21d13dc
Reviewed-on: https://chromium-review.googlesource.com/685811Reviewed-by: default avatarBo <boliu@chromium.org>
Reviewed-by: default avatarAndrew Grieve <agrieve@chromium.org>
Commit-Queue: Yoland Yan <yolandyan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#505868}
parent 347a627d
......@@ -18,6 +18,7 @@ import org.junit.runners.model.InitializationError;
import org.junit.runners.model.Statement;
import org.chromium.base.CollectionUtil;
import org.chromium.base.CommandLine;
import org.chromium.base.test.BaseTestResult.PreTestHook;
import org.chromium.base.test.util.DisableIfSkipCheck;
import org.chromium.base.test.util.MinAndroidSdkLevelSkipCheck;
......@@ -161,10 +162,18 @@ public class BaseJUnit4ClassRunner extends AndroidJUnit4ClassRunner {
notifier.fireTestFinished(child);
}
} else {
initCommandLineForTest();
super.run(notifier);
}
}
/**
* Override this method to change how test class runner initiate commandline flags
*/
protected void initCommandLineForTest() {
CommandLine.init(null);
}
@Override
protected void runChild(FrameworkMethod method, RunNotifier notifier) {
String testName = method.getName();
......
......@@ -8,6 +8,7 @@ import android.support.test.InstrumentationRegistry;
import org.junit.runners.model.InitializationError;
import org.chromium.base.BaseChromiumApplication;
import org.chromium.base.CollectionUtil;
import org.chromium.base.test.BaseJUnit4ClassRunner;
import org.chromium.base.test.BaseTestResult.PreTestHook;
......@@ -46,4 +47,8 @@ public class ChromeJUnit4ClassRunner extends BaseJUnit4ClassRunner {
new ChildProcessAllocatorSettingsHook(), Policies.getRegistrationHook());
}
@Override
protected void initCommandLineForTest() {
BaseChromiumApplication.initCommandLine(InstrumentationRegistry.getTargetContext());
}
}
......@@ -8,6 +8,7 @@ import android.support.test.InstrumentationRegistry;
import org.junit.runners.model.InitializationError;
import org.chromium.base.BaseChromiumApplication;
import org.chromium.base.CollectionUtil;
import org.chromium.base.CommandLine;
import org.chromium.base.test.BaseJUnit4ClassRunner;
......@@ -47,4 +48,9 @@ public class ContentJUnit4ClassRunner extends BaseJUnit4ClassRunner {
CommandLineFlags.getRegistrationHook(),
new ChildProcessAllocatorSettingsHook()});
}
@Override
protected void initCommandLineForTest() {
BaseChromiumApplication.initCommandLine(InstrumentationRegistry.getTargetContext());
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment