我怎麼能抓住這個AssertionFailedError異常,並打印到控制檯,上面寫着一個消息:如何捕獲AssertPathsEqual並將控制檯打印錯誤?
「預期的文本值 '55555' 但 '55556' 在/ xpathResult [1] /結果[2] /場[1]/field [1]/field [6]/text()[1]爲[testFileName]和[testName]「
我不完全確定如何從斷言中捕獲值而不必」hack 「並手動解析diff輸出字符串。我寧願有一個優雅的方法,而不是「黑客」方法。
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文本輸出嗎?
感謝您參考示例。我需要的是一個獲取Diff屬性的方法。當存在差異時,我想知道文件中差異的檢測位置以及差異。通過這些例子,我所能做的就是解析醜陋的diff輸出字符串以獲得這些屬性值。沒有其他辦法嗎? – djangofan 2009-12-07 19:08:41
據我所知,你想要的是一種方法來獲取diff的上下文來檢測XML文件的不同位置。我在那個方向上嘗試了一下,但是找不到方法。一種方法是通過使用DetailedDiff類中的方法「getAllDifferences」來獲取不同的XML節點,然後對它們進行比較。 DetailedDiff nd = new DetailedDiff(d); (Object o:nd.getAllDifferences()){ Difference f =(Difference)o; 節點c = f.getControlNodeDetail()。getNode(); 節點t = f.getTestNodeDetail()。getNode(); .. – sateesh 2009-12-08 08:17:48