The assertEquals() fails even though the both the strings are same…can someone help me figure out why?
public void testSet()
{
ByteArrayOutputStream outContent = new ByteArrayOutputStream();
System.setOut(new PrintStream(outContent));
instance.get();
String output = outContent.toString();
String input="i=1\r\n";
assertEquals(input,output);
}
get()
{
int i=1;
System.out.println("i="+i);
}
You are using
newlinein your print statement in yourget()method which is appending\r\nin the output buffer. This way you are getting `output = “i=1\r\n” which is not equal to “i=1”.Use the
print without newline i.e. print()as below:If you don’t want to use
print()method then truncate the\r\nfrom the output as below: