Get Command line arguments from Junit4 rules. |
||
Issue descriptionIn our Junit3 instrumentation tests we can specify Chrome command line options for a test base class, and, unless they are removed by a derived class or by an individual tests, they are applied to all tests in classes derived from that base class. The Junit4 instrumentation tests replace the test base classes with rule classes, but the test classes are not derived from the rule classes, so all the command line options have to be specified in each test, hence increasing maintenance load. Fix this by allowing annotations on rule classes that provide command line options. Assigning to myself since I have a fix for this.
,
Jun 19 2017
Have a look at my CL (https://chromium-review.googlesource.com/c/539563/) and let me know what you think; either as an intermediate step to using combined rules or as an alternative. I did wonder about combining rules, but the only thing I can see that does this is RuleChain, and it wasn't obvious to me that that would do what we want. John has just added you as a reviewer of the CL, beating me to it by a few seconds. Sorry I didn't do so in the first place.
,
Jun 19 2017
Oh, not a problem at all: ) RuleChain works, but syntactically is rather annoying and are getting deprecated, most importantly, we probably want a custom way to make sure some rules run before others (e.g. CommandLineFlag before activity launch) Reflectively searching for TestRule field is actually a pretty great way to resolve this issue!
,
Jun 21 2017
Once the initial implementation of this has landed there we should move the existing common command line switches (e.g. DISABLE_FIRST_RUN_EXPERIENCE) to the appropriate rules (in this case ChromeActivityTestRule), and remove them from the tests. I don't propose to do this in the initial CL.
,
Jun 22 2017
The following revision refers to this bug: https://chromium.googlesource.com/chromium/src.git/+/4b4ec5c8ec1ef6e2d76b116aae230ddec9b6451d commit 4b4ec5c8ec1ef6e2d76b116aae230ddec9b6451d Author: Anthony Berent <aberent@chromium.org> Date: Thu Jun 22 16:55:35 2017 Enable CommandLineFlags annonations on Rules. Enable CommandLineFlags.add and CommandLineFlags.remove on Junit4 Rules. The annotations are read in the order: 1. Annotations on Rule Classes and Rule Class Ancestors 2. Annotations on Test Class Ancestors 2. Annotations on Test Class 3 Annotations on Test method Meaning that annotations on the test class or method can remove command line flags set by rules. The order in which annotations on different rules are applied is undefined, but annotations on each rule's ancestors are read before annotations on the rule itself Note that if the @Rule annotation annotates a method (see http://junit.org/junit4/javadoc/4.12/org/junit/Rule.html) then this will only read CommandLine annotations on the formal return type of the method, and not the actual type of the returned rule. This CL also (as a test of this) adds command line flags to BottomSheetTestRule, and removes them from tests using this rule. BUG= 734553 Change-Id: I1501cb6ca4ae3963775b299b1695304e471ac0ab Reviewed-on: https://chromium-review.googlesource.com/539563 Commit-Queue: Anthony Berent <aberent@chromium.org> Reviewed-by: John Budorick <jbudorick@chromium.org> Reviewed-by: Yoland Yan <yolandyan@chromium.org> Reviewed-by: Bernhard Bauer <bauerb@chromium.org> Cr-Commit-Position: refs/heads/master@{#481568} [modify] https://crrev.com/4b4ec5c8ec1ef6e2d76b116aae230ddec9b6451d/base/test/android/javatests/src/org/chromium/base/test/util/CommandLineFlags.java [modify] https://crrev.com/4b4ec5c8ec1ef6e2d76b116aae230ddec9b6451d/chrome/android/javatests/src/org/chromium/chrome/browser/appmenu/ChromeHomeAppMenuTest.java [modify] https://crrev.com/4b4ec5c8ec1ef6e2d76b116aae230ddec9b6451d/chrome/android/javatests/src/org/chromium/chrome/browser/suggestions/SuggestionsBottomSheetTest.java [modify] https://crrev.com/4b4ec5c8ec1ef6e2d76b116aae230ddec9b6451d/chrome/android/javatests/src/org/chromium/chrome/browser/suggestions/SuggestionsBottomSheetUiCaptureTest.java [modify] https://crrev.com/4b4ec5c8ec1ef6e2d76b116aae230ddec9b6451d/chrome/android/javatests/src/org/chromium/chrome/browser/widget/bottomsheet/BottomSheetContentControllerTest.java [modify] https://crrev.com/4b4ec5c8ec1ef6e2d76b116aae230ddec9b6451d/chrome/android/javatests/src/org/chromium/chrome/browser/widget/bottomsheet/BottomSheetObserverTest.java [modify] https://crrev.com/4b4ec5c8ec1ef6e2d76b116aae230ddec9b6451d/chrome/test/android/javatests/src/org/chromium/chrome/test/BottomSheetTestRule.java [modify] https://crrev.com/4b4ec5c8ec1ef6e2d76b116aae230ddec9b6451d/testing/android/docs/junit4.md
,
Jun 22 2017
|
||
►
Sign in to add a comment |
||
Comment 1 by yolandyan@chromium.org
, Jun 19 2017