Take the 2-minute tour ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

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?

share|improve this question
    
Are you looking for a CLI or an API? If an API, what language? –  user246 Jun 15 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 at 6:31
    
Should it be automated procedure of validating or you consider only manual testing? –  olyv Jun 16 at 6:38
    
@olyv Automated. –  Mike John Jun 16 at 19:38

3 Answers 3

up vote 3 down vote accepted

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

share|improve this answer
    
This tool fixes the problems with the HTML but it doesn't tell me what are the errors. I just need to know if an HTML is valid or not. I don't need to fix the errors. –  Mike John Jun 17 at 4:27
1  

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).

share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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