Next, in the ExpectedFailure#apply(), when I do the base.evaluate(), I'm catching any Throwable (which includes AssertionError) and if the method is marked with the annotation @Deprecated, I ignore the error. You can perform whatever logic you like to decide whether you should ignore the error or not, based on version number, some text, etc. You can also pass a dynamically determined flag into ExpectedFailure to allow it to fail for certain version numbers:public void unmarshalledDocumentHasExpectedValue() { doc = unmarshaller.unmarshal(getResourceAsStream("mydoc.xml")); expectedFailure.setExpectedFailure(doc.getVersionNumber() < 3000); final ST title = doc.getTitle(); assertThat(doc.getTitle().toStringContent(), equalTo("Expected"));}有关更多示例,请参阅ExternalResource, 和 ExpectedExceptionFor further examples, see ExternalResource, and ExpectedException如果你想把你的测试标记为忽略而不是成功,它会变得有点复杂,因为测试在执行之前被忽略,所以你必须回顾性地将测试标记为忽略,这将涉及构建你自己的 Runner.首先,请参阅我对 的回答如何在套件中定义 JUnit 方法规则?.或者再问一个问题.If you want to mark you tests as Ignored rather than Success, it becomes a bit more complex, because tests are ignored before they are executed, so you have to retrospectively mark a test as ignored, which would involve constructing your own Runner. To give you a start, see my answer to How to define JUnit method rule in a suite?. Or ask another question. 这篇关于将单元测试标记为 JUnit 中的预期失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 09-06 03:35