I'm writing some JUnit tests that will use the XPath API to check to see if the node values for all possible nodes are correct in an XML document. Suppose all of these JUnit tests pass. Would it be reasonable to assume that the XML document was formed correctly? Would it be necessary to write another JUnit test that validates the XML document against a schema?
I would feel safer with a schema validation than with manual checks.
All the tags might be there, and they might all have valid values. But do your tests cover everything the schema covers? And will the next person to maintain this code be as thorough?
Do the tags have to be in a specific order?
Do you have enumerated types in the schema, and are all the valid values covered?
Presumably when used in the "real" application the messages will be validated against a schema.
So why not subject it to the same treatment in testing?
Catching an error in testing is always better than catching it in production. And if it can be detected by doing something as simple as validating against a schema, why wouldn't you?