?????????????????
?????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