Search code examples
javajunit

The method assertEquals(String, String) is undefined for the type TestJunit


I am new to JUnit. I just started working on JUnit and i am getting following error.

The method assertEquals(String, String) is undefined for the type TestJunit

and my Javacode:

import org.junit.Test;
import static org.junit.Assert.assertArrayEquals;

public class TestJunit {

    String message = "Hello World";
    MessageUtil messageutil = new MessageUtil(message);

    public void testPrintMessage()
    {
        assertEquals(message,messageutil.printMessage());

    }
}

please help me resolve this issue.


Solution

  • You imported

    import static org.junit.Assert.assertArrayEquals;
    

    but not

    import static org.junit.Assert.assertEquals;
    

    You could also import every static member of Assert with

    import static org.junit.Assert.*;
    

    Without these, Java thinks you are calling the method assertEquals defined in the class the code is declared in. Such a method does not exist.