????1????????(?汾3.0)
????Android??????????JUnit????????Robolectric???????Android????????л???????????????junit?????????????£?
????testCompile 'junit:junit:4.10'
????testCompile 'org.robolectric:robolectric:3.0'
?????????Build Variants?е?Test Artifact???Unit Tests??

??????Android Studio2.0?????????????????????????
????2??????γ???
??????Android studio??????Test?????????????TestDemoTest.
@RunWith(RobolectricGradleTestRunner.class)
@Config(constants = BuildConfig.class??
sdk = 21??
manifest = "src/main/AndroidManifest.xml"??
packageName = "cn.liucl.andoridunittestdemo"??
resourceDir = "res")
public class TestDemoTest {
public static final String TAG = TestDemoTest.class.getSimpleName();
private MainActivity mainActivity;
@Before
public void beforeTest() throws Exception {
System.out.println("before");
}
@Test
public void Testing() throws Exception {
System.out.println("Testing()");
}
}
??????1?д????????????????robolectric????????????????????????before????????????????????????У?????????Activity?????????????Test???????????????????case?????????????Robolectric cant found resource and AndroidManifest.xml???????????robolectric??????????manifest??????????Resources???б????????????????????????????Config????Config??????????SDK?汾????????????嵥?????????????????????????????
??????????????????????????????AndroidManifest??Application??Theme???android:theme="@style/Theme.AppCompat"
???????????????????????sdk??????????????????????????????????????????

???????????????
????3??????Activity
????Robolectric???????Activity???????????е????????????????????????
??????1???????????Activity
????Robolectric????Activity????????????????????Activity????Robolectric.setupActivity(MainActivity.class);???????
@Before
public void beforeTest() throws Exception {
System.out.println("before");
mainActivity = Robolectric.setupActivity(MainActivity.class);
}
@Test
public void Testing() throws Exception {
Assert.assertNotNull(mainActivity); //??????????
System.out.println("Testing()");
}
??????????Robolectric???????