您可以嘗試在try/catch塊內部構造斷言 - 至少在最初時 - 如果失敗時可以打印出其他信息。當我在測試本身中出現單元測試輸出中被掩蓋的問題時,我發現這提供了更有用的信息。如果這是問題,也許你不需要在單個測試中縮小範圍。如果上述失敗的assertEquals,所得到的輸出
assertEquals(null, objectToBeTested);
像這樣:
@Test
public void testYourTestName() throws Exception {
try {
//Code to prepare the object to be tested
assertNull("This is my null test", objectToBeTested);
} catch (Exception e) {
String failureMessage = "\n" + e.toString() + "\n";
for (StackTraceElement stackLine : e.getStackTrace()) {
failureMessage += (stackLine.toString() + "\n");
}
fail("Error: " + failureMessage);
}
}
或者,你可以使用的assertEquals測試,我發現有一點更有幫助的顯示,如本:
testMyTestName(com.myCompany.myApp.myPath.myTests):期望值<空> 但:< [email protected]>
順便說一句,我不知道如何運行某個類中存在的某個測試,但正如您發現的那樣,您可以縮小範圍以運行特定類中的所有測試。要運行在com.myCompany.myApp.myPath命名空間中SomeTestClass發現測試:
http://localhost:4502/system/sling/junit/com.myCompany.myApp.myPath.SomeTestClass.html
你能在http://svn.apache.org/repos/asf再現與吊帶集成測試樣品的問題/ sling/trunk/testing/samples/integration-tests /?這將有助於更好地縮小國際海事組織的範圍。 –