blob: 3c682922102d707bb028a024eba62c17da038738 [file] [log] [blame]
Bernardo Rufinoae81b1c2018-07-30 16:56:12 +01001This folder is for Robolectric tests inside the platform.
2
3To add a test class annotate it as follows:
4
5@RunWith(FrameworkRobolectricTestRunner.class)
6@Config(manifest = Config.NONE, sdk = 26)
7@SystemLoaderClasses({ClassUnderTest.class, DependencyClasses.class})
8@SystemLoaderPackages({"com.android.server.yourmodule"})
9
10Robolectric loads some classes that it decides from versioned jars of the framework. Since we are
11part of the framework some of our classes get loaded from these jars. This is NOT what we want, we
12want to test against what we wrote in the tree. Because of this we use a custom test runner,
13FrameworkRobolectricTestRunner, that bypasses these jars and loads certain classes from the system
14class loader.
15
16To specify which classes to load use either @SystemLoaderClasses or @SystemLoaderPackages. In
17practice:
18* You MUST put the class under test here.
19* If you encounter any exceptions that might be caused by a different version of the class being
20loaded, such as NoSuchMethodException, put the class involved in the exception in this annotation
21and try again.
22
23Check Android.mk file for more info.