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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using Jtidy I pass an InputSteam and then I tried to validate whether or not the XHTML code in the InputSteam is valid.

InputStream s = new ByteArrayInputStream(my_string).getBytes(StandardCharsets.UTF_8));

Tidy tidy = new Tidy();

tidy.parse(s, System.out);

I would like to validate my test, true or false instead of printing this to the console: 5 warnings, no errors were found!

If I get 1 error how do I make my JUnit reflect a fail?

I noticed that no matter what my string looks like it gets parsed as valid always I tried this:

String my_string = "TABLE width = 400 &&&& table height = ";

That gets parsed as valid without any errors.

share|improve this question
up vote 1 down vote accepted

Try replacing the last line with something like this:

tidy.parse(s, null);
share|improve this answer
tidy.parse(s, null); Gives me this compiler error: The method parse(InputStream, OutputStream) is ambiguous for the type Tidy. How can I fix it? Also Assert is depricated. – Mike John Jun 17 '14 at 3:48
Try using a cast. Or use a StringWriter instead of null. I assume you can figure out the assertion part on your own. – user246 Jun 17 '14 at 11:23

I had the same question/problem. This is how I solved it

    String validHtml = "some valid html";
    InputStream inputStream = new ByteArrayInputStream(validHtml.getBytes(StandardCharsets.UTF_8));

    Tidy tidy = new Tidy();

    tidy.parse(inputStream, null);

    System.out.println("errors "+tidy.getParseErrors());
    System.out.println("warnings "+tidy.getParseWarnings());
    assertTrue("HTML has errors and it should not.",tidy.getParseErrors()==0);

The trick is in setXMLTags(true)

share|improve this answer

Your Answer


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.