????????????????·
???????????? ???????[ 2014/6/6 13:33:43 ] ????????????????? ???????
????3??????????????
????http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html
????Maven2????????????????????????????Σ???????????????Щjava?????????Щ??????????λ??????????????????????classpath?μ??????????е?????????????????????????д??????????
???????????JUnit&Mockito
????JUnit
????JUnit?????Java??????????????
????2013??????????????????????????main??????????????JUnit??
????JUnit ???????????????????????????????????????????ж???????????????????????????????ж?????????????????????????????д?????????????????????
??????????????
// ???????
package com.chinacache.portal.service;
public class ReportService {
public boolean validateParams() {
}
public String sendReport(Long id) {
}
public String sendReport(Long id?? Date time) {
}
}
// ??????????
package com.chinacache.portal.service; // ????????????????? package
public class ReportServiceUnitTest { // ?????????? UnitTest (???????) ?? InteTest (???????) ??β
// ??????????? test ???????????????????????
@Test
public void testValidateParams() {
}
// ?????????????????????????????????
@Test
public void testSendReportLong() {
}
// ??????????????????????????????????????????ü??????к????????β?????? success??fail ??
@Test
public void testSendReportLongDateSuccess() {
}
// ?????????????????????????????????????????????????
@Test
public void testSendReportLongDateFail() {
}
}
|
????Mockito
????Mockito????????Java??mocking?????????????д??????????????????????API??????EasyMock??jMock??????????????к?У??????????????????????????????expectations????????????????mocking????“???-???”??????′????a??????????????????????????????????
????Mockito?????
List mock = mock(List.class);
when(mock.get(0)).thenReturn("one");
when(mock.get(1)).thenReturn("two");
someCodeThatInteractsWithMock();
verify(mock).clear();
EasyMock?????
List mock = createNiceMock(List.class);
expect(mock.get(0)).andStubReturn("one");
expect(mock.get(1)).andStubReturn("two");
mock.clear();
replay(mock);
someCodeThatInteractsWithMock();
verify(mock);
|
??????
???·???
??????????????????
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