Android???????: ??????????????
???????С?? ???????[ 2016/6/3 10:58:05 ] ??????????????? Android
???????????а?????????????£?????????cover???μ?????
????1????????????
????2???????????????
????3??JUnit
????4??Mockito
????5??Robolectric
????6??Dagger2
????7??????????app???????
????8???????bonus
??????????????
???????????????????????????????????????????????????????????????????????????????????????????????????????????????е??????????????????????????????д???????????????????????????????????????????????????????????????????????д????????????????“????????”??????????顢????????????????????????????????????????????????????в?????????????壬??????????OOP???????????????????????????????????????????????????????????????????????????????????д?????????????????????????£?????????????????????£?
????public class Calculator {
????public int add(int one?? int another) {
????//??????????????????????????
????return one + another;
????}
????}
???????????????? Calculator ??? add() ?????????????д???μ??????????
????public class CalculatorTest {
????public void testAdd() throws Exception {
????Calculator calculator = new Calculator();
????int sum = calculator.add(1?? 2);
????Assert.assertEquals(3?? sum);
????}
????}
????????? CalculatorTest ?? Calculator ????????????????? testAdd() ?? add() ?????????????????????????д???????????????????????public????д???????????????public????????????????????????????????????????????????????????public????????????????????????????????????????????public???????????????
????????????????????????????????????3???????????????????????
????Calculator calculator = new Calculator();
????int sum = calculator.add(1?? 2);
????Assert.assertEquals(3?? sum);
????????????????д??????????????Щ????????????????Java??????????? JUnit ?? TestNG ???????????е??????У??????JUnit 4?????????????????????????????????? Assert.assertEquals(3?? sum); ?????JUnit????????????????????????????? Assert ????Щassert??????????????????? assertEquals ?????? assertTrue ?? assertNotNull ????????JUnit???????????????????????????
????????????android project???????е??????
??????????????????android gradle project?У??????????????src/main/java?????????????????????????????src/test/java????????????????
???????е?package name????????????????????src package name??????£???????????????.test????????AndroidStudio???????????????????????????????package?????AndroidStudio???src??package????????????
?????? CalculatorTest ????????????? testAdd() ?????????Run testAdd()?? ??????????
????????????????????????????? Ctrl+Shift+R ???????У??????????????????????????????????????????????????????????????????????????????????? Ctrl+Shift+R ???????????????????в????????????????????????????????????????????????????????????в????????
???????н???????????????“Run”???tab???????е???????????????
??????????AndroidStudio???????У?????????????????? gradle testDebugUnitTest ???????? gradle testReleaseUnitTest ?????????debug??release?汾??unit testing????????????????????????в?????????в???????? ???????????н????????????
???????test case??????????project_root/app/build/reports/tests/debug/index.html ???xml???濴???????????????
??????????μ?????? github ?????????????clone????????????
??????
???·???
??????????????????
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