File tree 5 files changed +65
-4
lines changed
test/android/junit/src/org/chromium/base/test
5 files changed +65
-4
lines changed Original file line number Diff line number Diff line change @@ -4513,6 +4513,7 @@ if (is_android) {
4513
4513
4514
4514
deps = [
4515
4515
" :base_java" ,
4516
+ " :base_java_test_support" ,
4516
4517
" //testing/android/junit:junit_test_support" ,
4517
4518
" //third_party/android_support_test_runner:runner_java" ,
4518
4519
" //third_party/androidx:androidx_test_core_java" ,
@@ -4570,6 +4571,8 @@ if (is_android) {
4570
4571
" test/android/junit/src/org/chromium/base/test/util/CommandLineFlagsNoClassAnnotationCheckTest.java" ,
4571
4572
" test/android/junit/src/org/chromium/base/test/util/CommandLineFlagsWithClassAnnotationCheckTest.java" ,
4572
4573
" test/android/junit/src/org/chromium/base/test/util/DisableIfTest.java" ,
4574
+ " test/android/junit/src/org/chromium/base/test/util/DisabledTestForClassRobolectricTest.java" ,
4575
+ " test/android/junit/src/org/chromium/base/test/util/DisabledTestRobolectricTest.java" ,
4573
4576
" test/android/junit/src/org/chromium/base/test/util/RestrictionSkipCheckTest.java" ,
4574
4577
" test/android/junit/src/org/chromium/base/test/util/SkipCheckTest.java" ,
4575
4578
]
Original file line number Diff line number Diff line change 6
6
7
7
import androidx .test .core .app .ApplicationProvider ;
8
8
9
+ import org .junit .runners .model .FrameworkMethod ;
9
10
import org .junit .runners .model .InitializationError ;
10
11
import org .robolectric .DefaultTestLifecycle ;
11
12
import org .robolectric .TestLifecycle ;
16
17
import org .chromium .base .LifetimeAssert ;
17
18
import org .chromium .base .PathUtils ;
18
19
import org .chromium .base .metrics .UmaRecorderHolder ;
20
+ import org .chromium .base .test .util .DisabledTest ;
19
21
import org .chromium .testing .local .LocalRobolectricTestRunner ;
20
22
21
23
import java .lang .reflect .Method ;
@@ -61,4 +63,13 @@ public BaseRobolectricTestRunner(Class<?> testClass) throws InitializationError
61
63
protected Class <? extends TestLifecycle > getTestLifecycleClass () {
62
64
return BaseTestLifecycle .class ;
63
65
}
66
+
67
+ @ Override
68
+ protected boolean isIgnored (FrameworkMethod method ) {
69
+ if (super .isIgnored (method ) || method .getAnnotation (DisabledTest .class ) != null ) {
70
+ return true ;
71
+ }
72
+ Class <?> testSuiteClass = method .getDeclaringClass ();
73
+ return testSuiteClass .getAnnotation (DisabledTest .class ) != null ;
74
+ }
64
75
}
Original file line number Diff line number Diff line change
1
+ // Copyright 2022 The Chromium Authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style license that can be
3
+ // found in the LICENSE file.
4
+
5
+ package org .chromium .base .test .util ;
6
+
7
+ import org .junit .Assert ;
8
+ import org .junit .Test ;
9
+ import org .junit .runner .RunWith ;
10
+ import org .robolectric .annotation .Config ;
11
+
12
+ import org .chromium .base .test .BaseRobolectricTestRunner ;
13
+
14
+ /** Unit tests for the DisabledTest annotation in Robolectric tests. */
15
+ @ RunWith (BaseRobolectricTestRunner .class )
16
+ @ Config (manifest = Config .NONE )
17
+ @ DisabledTest (message = "This test suite should be disabled" )
18
+ public class DisabledTestForClassRobolectricTest {
19
+ @ Test
20
+ public void testTestsInDisabledSuitesAreNotExecuted () {
21
+ Assert .fail ("Tests suites marked with @DisabledTest annotation should not be executed!" );
22
+ }
23
+ }
Original file line number Diff line number Diff line change
1
+ // Copyright 2022 The Chromium Authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style license that can be
3
+ // found in the LICENSE file.
4
+
5
+ package org .chromium .base .test .util ;
6
+
7
+ import org .junit .Assert ;
8
+ import org .junit .Test ;
9
+ import org .junit .runner .RunWith ;
10
+ import org .robolectric .annotation .Config ;
11
+
12
+ import org .chromium .base .test .BaseRobolectricTestRunner ;
13
+
14
+ /** Unit tests for the DisabledTest annotation in Robolectric tests. */
15
+ @ RunWith (BaseRobolectricTestRunner .class )
16
+ @ Config (manifest = Config .NONE )
17
+ public class DisabledTestRobolectricTest {
18
+ @ Test
19
+ @ DisabledTest (message = "This test should be disabled" )
20
+ public void testDisabledTestAreNotExecuted () {
21
+ Assert .fail ("Tests marked with @DisabledTest annotation should not be executed!" );
22
+ }
23
+ }
Original file line number Diff line number Diff line change @@ -26,10 +26,11 @@ There are a number of different ways to do so:
26
26
method name for GTest-based tests, ` @unittest.skip ` for Python-based tests,
27
27
or using the
28
28
[ DisabledTest] ( ../../base/test/android/javatests/src/org/chromium/base/test/DisabledTest.java )
29
- annotation for JUnit-based Java tests. In these cases, you don't run the
30
- test by default, but you can determine the list of disabled tests at
31
- runtime because the tests are present in the executable, and you may still
32
- be able to force the test to be run via a command-line flag.
29
+ annotation for JUnit-based Java tests (this works in both instrumentation
30
+ and Robolectric tests). In these cases, you don't run the test by default,
31
+ but you can determine the list of disabled tests at runtime because the
32
+ tests are present in the executable, and you may still be able to force the
33
+ test to be run via a command-line flag.
33
34
34
35
* Fourth, for test frameworks that support
35
36
[ expectations files or filter files] ( https://bit.ly/chromium-test-list-format ) ,
You can’t perform that action at this time.
0 commit comments