I need to use the method org.junit.Assert.assertEquals
in my test script but the Assert
remains red and shows as an unresolved symbol. I do installed the junit
and I don't know why only the Assert
remains unresolved. I'm new to java btw. Here is the screenshot of my code
Really need some help! Thank you so much!
PS: I saw there was another post about this issue and resolved by import static org.junit.Assert.*;
but this doesn't work at my side.
CodePudding user response:
In JUnit 5, you can import assertion methods like follows:
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class UnitTest {
// we can use JUnit 5's @Test annotation
@Test
void testEquals() {
assertEquals(1, 1);
}
}
In JUnit 4, assertions use the imports as you are using: import static org.junit.Assert.assertEquals;
CodePudding user response:
Add spring boot starter test maven dependency and then do static import.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
import static org.junit.jupiter.api.Assertions.*;