开发者

Junit returning an error on assertTrue string comparison

开发者 https://www.devze.com 2023-03-10 12:00 出处:网络
StringWriter resul开发者_如何学Got = runMethod.getOutput(); String expected = \"<3>textValue</3>\"
     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

精彩评论

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