1 // Copyright 2020 The Chromium Authors 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 java.lang.annotation.ElementType; 8 import java.lang.annotation.Retention; 9 import java.lang.annotation.RetentionPolicy; 10 import java.lang.annotation.Target; 11 12 /** 13 * Annotation to indicate that this collection of tests is safe to run in batches, where the 14 * Instrumentation Runner (and hence the process) does not need to be restarted between these tests. 15 * 16 * The value passed to this annotation determines which test suites may be run together in the same 17 * batch - batches that share a batch name will run in the same Instrumentation invocation. The 18 * default value (empty) means the suite runs as its own batch, and the process is restarted before 19 * and after the suite. 20 * 21 * This makes the tests run significantly faster, but you must be careful not to persist changes to 22 * global state that could cause other tests in the batch to fail. 23 * 24 * @Before/@After will run as expected before/after each test method. 25 * @BeforeClass/@AfterClass may be used for one-time initialization across all tests within a single 26 * suite. Tests wishing to share one-time initialization across suites in the same batch will need 27 * to explicitly coordinate. 28 * 29 * Tests that are safe to run in batch should have this annotation. 30 * 31 * Tests should have either {@link Batch} or {@link DoNotBatch} annotation. 32 */ 33 @Target(ElementType.TYPE) 34 @Retention(RetentionPolicy.RUNTIME) 35 public @interface Batch { 36 value()37 public String value(); 38 39 /** 40 * Batch name for test suites that are not safe to run batched across multiple suites. The 41 * process will not be restarted before each test within this suite, but will be restarted 42 * before and after this suite runs. 43 */ 44 public static final String PER_CLASS = ""; 45 46 /** 47 * Globally shared name for unit tests that can all be batched together. 48 * 49 * Unit tests must be careful not to persist any changes to global state, or flakes are likely 50 * to occur. 51 * 52 * An exception to this is loading Chrome's native library (eg. using NativeLibraryTestUtils). 53 * Your unit tests must assume that the native library may have already been loaded by another 54 * test. 55 */ 56 public static final String UNIT_TESTS = "UnitTests"; 57 } 58