I have a Spring controller that returns XHTML, what’s the easiest way to setup a JUnit test that verifies that the XHTML is valid? I’d also like to verify certain elements are present.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
The only way is to parse the output. I’ve used dom4j in my jUnit tests. Then you can use Xpath or DOM to extract the elements you want and test them.
If you’re not already using a parser, it can take a little messing around to get it going. But once you’ve got it, it’s very handy, and you can write all sorts of great tests. If using parsers is new to you, perhaps take a look at the dom4j quickstart guide.