我在 Eclipse 中使用 Junit4。
测试运行成功。但有时,日食会挂起并关闭工作区。
我必须将我的代码部署到声纳詹金斯。我无法使用 Junit 类进行稳定构建。我的 Junit 测试用例如下。
@RunWith(PowerMockRunner.class)
@PrepareForTest({UtilityFunctions.class,EmergencyDoDao.class,
EmergencyDoService.class,
EmergencyDoExport.class,EmergencyDoBusinessManager.class })
public class EmergencyDoServiceTest {
/**
* Run the EmergencyDoService() constructor test.
*
* @generatedBy CodePro at 9/19/13 12:00 PM
*/
@Test
public void testEmergencyDoService_1()
throws Exception {
EmergencyDoService result = new EmergencyDoService();
assertNotNull(result);
// add additional test code here
}
@Test
public void testGetEmergencyDoService_1()
throws Exception {
String dc = "5854";
String beginDate = "1/1/2011 00:00 AM";
String endDate = "9/18/2013 00:00 AM";
String doStr = "*";
String doStatus = "All";
String shipment = "*";
boolean isExport = false;
String sortBy = "CreatedDate,OrderId";
String fileType = "";
BigDecimal scheduleId = null;
BigDecimal jobId = null;
EmergencyDoInputDTO inputDto = new EmergencyDoInputDTO();
inputDto.setDc(dc);
inputDto.setBeginDate(CommonUtil.convertToSqlTimeStamp(beginDate));
inputDto.setEndDate(CommonUtil.convertToSqlTimeStamp(endDate));
inputDto.setDoStr(doStr);
inputDto.setDoStatus(doStatus);
inputDto.setShipment(shipment);
inputDto.setSortBy(sortBy);
inputDto.setExport(isExport);
inputDto.setFileType(fileType);
EmergencyDoMockDAO.mockgetEmergencyDo(inputDto,scheduleId,jobId);
Response result = EmergencyDoService.getEmergencyDoService(dc, beginDate, endDate, doStr, doStatus, shipment, isExport, sortBy, fileType, scheduleId, jobId);
String output = result.getEntity().toString();
Assert.assertEquals(true,output.contains("\"result\": \"Success\""));
}
@Before
public void setUp()
throws Exception {
// add additional set up code here
}
/**
* Perform post-test clean-up.
*
* @throws Exception
* if the clean-up fails for some reason
*
* @generatedBy CodePro at 9/19/13 12:00 PM
*/
@After
public void tearDown()
throws Exception {
// Add additional tear down code here
}
/**
* Launch the test.
*
* @param args the command line arguments
*
* @generatedBy CodePro at 9/19/13 12:00 PM
*/
public static void main(String[] args) {
new org.junit.runner.JUnitCore().run(EmergencyDoServiceTest.class);
}
经过一番挣扎,我发现在junit类的拆解中,我们可以添加代码来清理资源。
任何人都可以建议我如何在 Junit 中清理上述资源,以便我可以在 jenkins 中有一个稳定的 bulid。