开发者

Verify XHTML is valid in a JUnit test?

开发者 https://www.devze.com 2022-12-22 20:54 出处:网络
I have a Spring controller that returns XHTML, what\'s the easiest way to setup a JUnit开发者_StackOverflow中文版 test that verifies that the XHTML is valid?I\'d also like to verify certain elements a

I have a Spring controller that returns XHTML, what's the easiest way to setup a JUnit开发者_StackOverflow中文版 test that verifies that the XHTML is valid? I'd also like to verify certain elements are present.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消