StringWriter result = runMethod.getOutput();
String expected = "<3>textValue</3>"
assertTrue("Should have contained the required result", result.toString().contains(expected));
为什么Junit会在这里返回错误?
答案 0 :(得分:3)
我刚试过这个,它运行正常。
如果字符串不匹配,则会出现以下错误。 java.lang.AssertionError:应该包含所需的结果
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));
}
}