I am testing a class that takes 1 string and generates an HTML page around that string.

So I pass it the string Math and it returns to me a whole HTML page as a string containing that Word and with matching <td></td> a header <h3></h3> and a form.

How do I validate this as a valid HTML code?

  • Are you looking for a CLI or an API? If an API, what language?
    – user246
    Jun 15, 2014 at 22:33
  • I'm doing my testing in eclipse. If there is an API that I can use to test this java code I will take it. Again I am testing java code that makes HMTL code as a string.
    – Mike John
    Jun 16, 2014 at 6:31
  • Should it be automated procedure of validating or you consider only manual testing?
    – olyv
    Jun 16, 2014 at 6:38
  • @olyv Automated.
    – Mike John
    Jun 16, 2014 at 19:38

5 Answers 5


I would create a jUnit test using a HTML validator like jTidy API, like suggested in https://stackoverflow.com/questions/4217801/a-html-validator-in-java

Also see running tests like this in Eclipse: http://help.eclipse.org/juno/topic/org.eclipse.jdt.doc.user/gettingStarted/qs-junit.htm


Yes, it is important to validate HTML. There are W3C standards against which you can validate it.

You can use various tools like the W3C Html validator, or Web Developer addon of FireFox.

There are several such paid an unpaid tools that can help you validate your HTML. It helps in page optimization and SEO.


Once the HTML page is generated try validating it with W3C HTML validator!

Its maven info is:


Agree with suggestion to use validator. One more approach is just to parse xml using xpath. Test will fail if document structure is broken. As a regression approach you can create some html files and compare those pattern files with newly generated. For example by using bash (or smth. similar in Windows OS).


Apache JMeter provides HTML Assertion which uses JTidy HTML syntax checker.

You can use JMeter to test your generated pages as per How to Use JMeter Assertions in 3 Easy Steps. It can be launched as command-line application, integrated into Ant, Maven, Jenkins, build or launched from Java code.

If you don't need the superpower of JMeter you can just extract HTML Assertion related code as it's free and open source product.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.