?????????????????
?????youly ???????[ 2017/7/11 10:05:08 ] ??????????????? ??????? ?????
??????????????
????????????
?????????Wikipedia ?????????
????????????械???????????????????蟹???????
??????????????蟹??????????椋�????小??????胁????????????????????校?unit ???????? class/method??
????????? unit ???????????????????? mock/stub ???????????stub??mock???????????martinfowler??????Mocks Aren’t Stubs??
?????????????????胁????????写??
???????????????????????????????????OOP??????????????????????????
????State????????????????????????????????
????Behavior??????????????????????????????????????
????Unit testing ???????????????????????? state assert ?? behavior verification??
??????????????????????????械?位??
???????????????????????????危???????????????校?
?????????????????????????????????/??楦�???
?????????????????????????????绲�???????
????e??????????????????????????????????????????????????????????????????????泻????????
??????????????????????????????????????????泄????
??????????????
?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????写???????????????????????????????
?????????????????????????????????????????????????写????????????????????????????????????写???????效??????
????????????????????????????????????????????????????????????????
?????????????????????????????????????????????
???????”?????????”?校???????????????????????????????锌???????????????????????????bugfix??????????????????????锟�?Google testing: Just Say No to More End-to-End Tests??
??
?????????????????
????mock???????????????????写???????????
????????????????????????????????????????????????????????????????????
??????????????斜????械????????????????????????
????????????????????????????????????????????????????娣�????????????????????????????????????????胁????娣�????
????????????????
????1?????????????娣�
??????????
??src/
?????????? main
?????? ?????? java
?????? ?????? resources
?????????? test
?????????? java
?????????? resources
?????????慰?maven????????
??????????????
??// ????????Test??尾
????public class TokenServiceTest extends AbstractTestCase {
????@Resource
????private TokenService tokenService;
????// ??????????Test??尾
????@Test
????public void insertTest() {
????MockUp<TokenDao> tokenDaoMockUp = new MockUp<TokenDao>() {
????@Mock
????Integer insert(Token token) {
????return 1;
????}
????};
????ReflectionTestUtils.setField(tokenService?? "tokenDao"?? tokenDaoMockUp.getMockInstance());
????tokenService.insert();
????}
????}
???????????????????????????????????????????写?????????????????????
????1) web??
??????? PATH??REQUEST_METHOD ??????????????? RESPONSE_CODE???????????????????????????????????????泻?????????????????????????
????2) facade??
???????????校?椋�????????????????????
????3) service/component??
???????????????????????????????mock??????????????
????4) cache??
?????????????????????????????写??????????????????????????????????????
????5) dao??
???????sql?????????????????????????????????????????????????????????
????????????????
??????????????????????????校???械???????????review?????
????2????????????????
????????????些?????????????????????芯????????????????????
????TestNG: a testing framework inspired from JUnit and NUnit but introducing some new functionalities?? ?????http://testng.org/doc/
????jmockit: includes APIs for mocking?? faking?? and integration testing?? and a code coverage tool. ?????http://jmockit.org/about.html??API ???????锟�?
????3??????????
???????????????????????????????????????????????????
?????????????
????????????????????????锟�???????????????????
??????
???路???
??????????????????
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