Cannot find symbol assertEquals
assertEquals
is a static method. Since you can't use static methods without importing them explicitly in a static way, you have to use either:
import org.junit.Assert;
...
Assert.assertEquals(...)
or:
import static org.junit.Assert.assertEquals;
...
assertEquals(...)
For @Test
it's a little bit different. @Test
is an annotation as you can see by the @
. Annotations are imported like classes.
So you should import it like:
import org.junit.Test;
Generally avoid using wildcards on imports like import org.junit.*
. For reasons see Why is using a wild card with a Java import statement bad?.
JUnit 5 Jupiter
In JUnit 5 the package name has changed and the Assertions are at org.junit.jupiter.api.Assertions
and Assumptions at org.junit.jupiter.api.Assumptions
So you have to add the following static import
:
import static org.junit.jupiter.api.Assertions.*;
See also http://junit.org/junit5/docs/current/user-guide/#writing-tests-assertions