您可以尝试在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 /?这将有助于更好地缩小国际海事组织的范围。 –