Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 521235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:13:45+00:00 2026-05-13T08:13:45+00:00

How could I catch this AssertionFailedError and print to the console an message that

  • 0

How could I catch this AssertionFailedError and print to the console an message that says:

“Expected text value ‘55555’ but was ‘55556’ at /xpathResult[1]/result[2]/field[1]/field[1]/field[6]/text()[1] for [testFileName] and [testName]”

I’m not exactly sure how to catch the values out from the assertion without having to “hack” and manually parse the diff output string. I would rather have an elegant method rather than a “hack” method.

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)

Am I going to have to write my own DiffDescriber class that parses the Diff text output?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T08:13:45+00:00Added an answer on May 13, 2026 at 8:13 am

    You can catch the AssertionError to get the detailed error message to the console.

    You can try something like this :

           try{
               // say you are comparing FileReader objects that
               // refer to XML documents
               assertXMLEqual(filereader1, filereader2); 
            } catch (final SAXException e) {
               // show faiulre message
            } catch (final IOException e) {
               // show failure message
            } catch (final AssertionError e) {
                System.err.println(e.toString());
            }
    

    But I think rather than catching AssertionError it is better to get more details about
    assertion failure by making use of the class “Diff” (from org.custommonkey.xmlunit).
    You can use this class to check if XML documents being compared are similar
    (or identical) and to get more details about the difference. You can also use
    the DetailedDiff class to get a detailed diff.

    Check Example4 and Example5 from the
    XMLUnit documentation. These examples show the usage of Diff and DetailedDiff.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.