开发者

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));
    }

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜