???????????????????????д????????????????У????????????????????????????????????????????????????12?????????????д??????????????????????????????????????????????????????????????????????????????????????????????е???????????????????????????Щ???????????μ???????? - ???????д???????
????????м??????????????
????1????????????????????
????2?????????????????
????3??Android????????????

????????????????????????з?????д??????????????????????????????????У????к???????д???????????????????μ??? - ????????????????д?????????д?????????????????????????????????????????????????????????? - ?????????????????д????????????д??????????????顣????????????TDD??????????????????????????????????TestCase?????????д?μ?????????б????????????Debug?????????????????????????????????TDD - TestDriveDevelopment(????????????)????TDD???????????????????????????????????????2?????????????????1??1??????
????????????TDD?????TDD??????
???????????????????????????????????????????????????????? "unit-test"????????????????????????????????????????????????????????????????????????磺???? boolean StringUtil.isEmpty(String str) ??????????????????ж????????????????????????????????Щ???????????????????????????
????assertTrue(StringUtil.isEmpty(null))
????assertTrue(StringUtil.isEmpty(""))
????assertFalse(StringUtil.isEmpty("any string"))
????...
????????????????????????????????д?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????з??????????????????????????е??????????????У??????????????Mock?????е???????????????????????????????????
// ????·????????????????????????????
public class ServiceTableImpl implements ServiceTable {
// ???????Id??????????
private ClientFactory referenceClient;
// ??????????DAO??????????????ID????????????????
private AppInfoDAO appInfoDAO;
@Override
public Service findService(String method) throws Exception {
if (method == null) {
logger.info("request method is null");
return null;
}
// ??????????ServiceID
AppInfo appInfo = appInfoDAO.getAppInfoByMethod(method);
if (appInfo == null || appInfo.getServiceId() == null) {
raiseException("service-id not found");
}
String serviceId = appInfo.getServiceId();
// ????ServiceID???????
service = referenceClient.getService(serviceId);
if (service == null) {
raiseException("can't find service");
}
return service;
}
}
?????1??ServiceTablel ???????????·?????????????????(method)???????????(Service)??
?????2???????????????????????TestCase????????????????????
????????????????? boolean StringUtil.isEmpty(String str) ??????д?????????????????
????ServiceTable servcieTable = new ServiceTableImpl();
????Service service = servcieTable.findService("a exist method");
????// expect not null
????assertNotNull(service);
????// expect exception
????Service service = servcieTable.findService("not exist method");
????fail();