Reputation: 165
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.
Upvotes: 15
Views: 41154
Reputation: 330
For Junit 5, I had to add following dependencies in my spring boot pom.xml files.
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<scope>test</scope>
</dependency>
Upvotes: -1
Reputation: 280122
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.
Upvotes: 31