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