Junit returning an error on assertTrue string comparison
StringWriter resul开发者_如何学Got = 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 ?
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));
}
}
精彩评论