Pan
Pan

Reputation: 6655

Junit returning an error on assertTrue string comparison

     StringWriter result = runMethod.getOutput();
   String expected = "<3>textValue</3>"
    assertTrue("Should have contained the required result", result.toString().contains(expected));

Why does Junit return an error here ?

Upvotes: 1

Views: 5880

Answers (1)

Deepak
Deepak

Reputation: 164

I just tried this and it works fine.

It gives the following error if the string does not match. java.lang.AssertionError: Should have contained the required result

import static org.junit.Assert.assertTrue;

import java.io.StringWriter;

import org.junit.Test;

public class XYZ
{

    @Test
    public void test()
    {

        StringWriter result = new StringWriter();
        result.append("<3>textValue</3>");
        String expected = "<3>textValue</3>";
        assertTrue("Should have contained the required result", result.toString().contains(expected));
    }

}

Upvotes: 3

Related Questions