Jung-Hyun
Jung-Hyun

Reputation: 353

junit - Expected and actual values are same but the test result is failure

Expected and actual values are same but the test result is failure in JUnit test. I don't know why this happens. Codes and result image are attached. One more weird thing is that there are error marks in the packages even though the source codes do not have any errors. An image about this is also attached). I guess two things are related each other. How can I solve this problem? Thanks.If you need more information, please ask me.

package tests;

import junit.framework.TestCase;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import net.n3.nanoxml.*;

public class NanoSetAttr3_wy_v1Tests extends TestCase {

    public void test0() throws Exception {
        //setattr3.out
        String result;
        ByteArrayOutputStream byteBuffer;

        byteBuffer = new ByteArrayOutputStream();
        System.setOut(new PrintStream(byteBuffer));
        try{
            SetAttr3_wy_v1.main(new String[] {});
        }catch (Throwable t) {
            t.printStackTrace(System.out);
        }
        result = new String(byteBuffer.toByteArray());
        assertEquals(result, "<FOO Weight=\"80\"/>");
    }

}

junit compares results package error marks

Upvotes: 1

Views: 4121

Answers (1)

jdigital
jdigital

Reputation: 12266

If you look closely at the Expected and Actual windows, you'll see that Expected has two lines and Actual has one. This means that the Expected output has a newline but the Actual output does not.

Regarding the error marks, open up Problems window for details (if you're not using Eclipse, there should be something similar).

Upvotes: 5

Related Questions