JAVA

[junit]The import org.junit.jupiter cannot be resolved Error

애드망3 2021. 5. 14. 08:30

junit으로 테스트를 진행하던 중 아래와 같은 import 에러가 발생했습니다

The import org.junit.jupiter

해당 프로젝트는 junit3로 테스트를 진행하라고 알려줬지만 해당 라이브러리와

Build Path -> Configure Build Path

Configure Build Path

Libraries에서 JUnit3을 확인했지만 문제가 없었습니다

Junit3

답은 "org.junit.jupiter"는 JUnit5 라이브러리에서 제공하는 기능으로

해당 라이브러리를 Maven에 추가해야 합니다

 

junit-jupiter-api 5.7.0

mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api/5.7.0

junit-jupiter-engine 5.7.0

mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-engine/5.7.0

작성 기준 유저들이 많이 사용한 버전으로 maven에 추가했습니다

org.junit.jupiter

코드

<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api -->
<dependency>
	<groupId>org.junit.jupiter</groupId>
	<artifactId>junit-jupiter-api</artifactId>
	<version>5.7.0</version>
	<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-engine -->
<dependency>
	<groupId>org.junit.jupiter</groupId>
	<artifactId>junit-jupiter-engine</artifactId>
	<version>5.7.0</version>
	<scope>test</scope>
</dependency>

위 코드를 추가 후에 프로젝트 우클릭 -> 메이븐 클린 -> 메이븐 업데이트 순으로 진행하면

The import org.junit.jupiter cannot be resoloved error 사라진 것을 확인할 수 있습니다

 

AssertionFailedError: No tests found 더보기

더보기

주의사항

AssertionFailedError: No tests found error의 경우

테스트 메서드의 경우 이름은 항상 "test" 시작해야 한다

@Test
public void testMyExample() throws Exception {
//Test Code
}

 

 

참고

stackoverflow.com/questions/51046506/how-to-fix-the-import-org-junit-jupiter