Ask the Penguin! XML and JUnit

Tagged:
Inspired by atrox's post on Junit at developerWorks, here is one I have been kind of grappling with lately. Does anyone have a good strategy for doing JUnit tests of XML output? I mean, given things like variable whitespace meaning and variable extended namespacing, it would be really great if I could generate and XML document then have a tool to let me, say, assert a bunch of XPath queries easily. I haven't found anytying that really makes doing flexible structural/data checks of XML output easy. I am kind of wondering if this is something I should write for myself.

Comments

RE: Ask the Penguin! XML and JUnit

I got nothing.

RE: Ask the Penguin! XML and JUnit

Marshall your docs into objects and then assert on them? Would work for data checks, not sure about structural/whitespace (not really sure what you mean to check there).

RE: Ask the Penguin! XML and JUnit

Yeah. The thing is, in a world where: [mytag] foo [/mytag] is the same as [mytag] foo [/mytag] Doing checks for equality is kind of hard. You also have issues with namespacings and tag orders: [thiers:tag] foo [/theirs:tag] [mine:tag] bar [/mine:tag] vs the inverse order, etc. I am thinking about putting together a toolkit for doing this kind of checking. Something that is a mix of XPATH and some re-structured string tests.

RE: Ask the Penguin! XML and JUnit

Just use Assert.assertTrue(true); and all your tests will pass just fine ;).

RE: Ask the Penguin! XML and JUnit

XMLUnit XMLUnit

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.