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.
IIRC assertEquals() succeeds if both strings are null. If this is not what you want then call assertNotNull() as well.
assertEquals. Asserts that two objects are equal. If they are not, an AssertionError is thrown with the given message. If expected and actual are null , they are considered equal.
Use assertThat instead An alternative option to assertEquals is assertThat .
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With