문제

The two approaches I usually follow are:

  1. Convert the HTML to a string, and then test it against a target string. The problem with this approach is that it is too brittle, and there'll be very frequent false negatives due to say, things like extra whitespace somewhere.

  2. Convert the HTML to a string and parse it back as an XML, and then use XPath queries to assert on specific nodes. This approach works well but not all HTML comes with closing tags and parsing it as XML fails in such cases.

Both these approaches have serious flaws. I imagine there must be a well-established approach (or approaches) for this sort of tests. What is it?

도움이 되었습니까?

해결책

You could use jsoup or JTidy instead of XML parsing and use your second strategy.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top