System.out.println()的JUnit測(cè)試我需要為一個(gè)設(shè)計(jì)不佳的舊應(yīng)用程序編寫JUnit測(cè)試,該應(yīng)用程序正在為標(biāo)準(zhǔn)輸出編寫大量錯(cuò)誤消息。當(dāng)getResponse(String request)方法的正確行為-它返回一個(gè)XML響應(yīng):@BeforeClasspublic static void setUpClass() throws Exception {
Properties queries = loadPropertiesFile("requests.properties");
Properties responses = loadPropertiesFile("responses.properties");
instance = new ResponseGenerator(queries, responses);}@Testpublic void testGetResponse() {
String request = "<some>request</some>";
String expResult = "<some>response</some>";
String result = instance.getResponse(request);
assertEquals(expResult, result);}但是,當(dāng)它得到格式錯(cuò)誤的xml或不理解它返回的請(qǐng)求時(shí)null寫一些東西到標(biāo)準(zhǔn)輸出。是否有任何方法來斷言JUnit中的控制臺(tái)輸出?如:System.out.println("match found: " + strExpr);System.out.println("xml not well formed: " + e.getMessage());
System.out.println()的JUnit測(cè)試
波斯汪
2019-06-20 16:31:56