Robolectric?????????
?????liucloo ???????[ 2016/5/30 11:15:37 ] ?????????????????? ???????
????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???????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11