我怎么能捕捉到这个 AssertionFailedError 并向控制台打印一条消息:
“预期的文本值 '55555' 但在 /xpathResult[1]/result[2]/field[1]/field[1]/field[6]/text()[1] 中为 [testFileName] 和[测试名称]"
我不确定如何从断言中捕获值而不必“破解”并手动解析差异输出字符串。我宁愿有一种优雅的方法,而不是一种“hack”方法。
junit.framework.AssertionFailedError: org.custommonkey.xmlunit.Diff
[different] Expected text value '55555' but was '55556' - comparing <field ...>55555</field> at /xpathResult[1]/result[2]/field[1]/field[1]/field[6]/text()[1] to <field ...>55556</field> at /xpathResult[1]/result[2]/field[1]/field[1]/field[6]/text()[1]
at junit.framework.Assert.fail(Assert.java:47)
at org.custommonkey.xmlunit.XMLAssert.assertXMLEqual(XMLAssert.java:125)
at org.custommonkey.xmlunit.XMLAssert.assertXMLEqual(XMLAssert.java:113)
at org.custommonkey.xmlunit.XMLAssert.assertXpathEquality(XMLAssert.java:582)
at org.custommonkey.xmlunit.XMLAssert.assertXpathsEqual(XMLAssert.java:453)
at org.custommonkey.xmlunit.XMLAssert.assertXpathsEqual(XMLAssert.java:435)
at org.custommonkey.xmlunit.XMLTestCase.assertXpathsEqual(XMLTestCase.java:454)
at tst.PatrolTests.compareXMLEqualityToLastTest(PatrolTests.java:353)
at tst.PatrolTests.doPlate(PatrolTests.java:141)
at tst.PatrolTests.testPlate(PatrolTests.java:117)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at junit.framework.TestCase.runTest(TestCase.java:168)
at junit.framework.TestCase.runBare(TestCase.java:134)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:232)
at junit.framework.TestSuite.run(TestSuite.java:227)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:79)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
我是否必须编写自己的 DiffDescriber 类来解析 Diff 文本输出?