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 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.setXHTML(true);

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

1 Answer 1

up vote 0 down vote accepted

Try replacing the last line with something like this:

tidy.setErrout(null);
tidy.parse(s, null);
Assert.assertEquals(0,tidy.getParseErrors());
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 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 at 11:23

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.