Java의 단위 테스팅(unit testing) 도구이며, 대표적인 Testing Framework다.
jar파일로 되어있다.
Testing 결과를 단순히 문서로 남기는 것이 아니라, TestClass를 그대로 남김으로써
추후 개발자에게 테스트 방법 및 클래스의 히스토리를 넘겨줄 수 있다.
어노테이션으로 간결하게 사용할 수 있다.
JUnit Annotation
@Test : 해당 Method는 Test대상 메소드다.
@BeforeClass : 해당 테스트가 시작 전에 딱 한 번씩만 수행되도록 지정한다.
@AfterClass : 해당 테스트가 끝나고 딱 한번씩만 수행되도록 지정한다.
@Before : 해당 테스가 시작되기 전에 작업할 내용을 호출한다.
@After : 해당 테스트가 끝난 후에 작업할 내용을 호출한다.
@Ignore : TestClass를 무시할 수 있다.
1. 빌드오류
현재 STS3에서 JUnit으로 테스트를 해보려고 하는데 Build오류가 난다.
프로젝트 우클릭 -> properties -> java build path -> libraries
또는,
프로젝트 우클릭 -> build path -> configure build path -> libraries
여기서 Add Library 에서 JUnit을 추가해줘야 한다.
프로젝트 생성시, 분명 추가해줬는데 제대로 인식이 안되는 듯 하다...
2. 어노테이션이 안먹힐 때
테스트케이스 작성시, @RunWith(SpringRunner.class) 가 먹히지 않아서
따로 pom.xml에 dependendy추가를 해줬다.
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>5.0.7.RELEASE</version>
</dependency>
@SpringBootTest 도 안먹혀서 pom.xml에 있는 dependency를 수정해줬다.
spring-boot-starter-test 에 있는 <scope>test</scope>을 제거해주면 된다.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<!-- <scope>test</scope> @springboottest 어노테이션 안먹혀서 주석처리 -->
</dependency>
3. JUnit class not found 에러
JUnit으로 테스트 시행시, 에러가 뜨고 콘솔창에 먼 에러가 났다고 뜬다.
build path 에서 maven 과 JRE의 순서를 바꿔보았지만.. 해결이 안됨
junit version을 4.9로 올려봐도 안됨 (https://kyome.tistory.com/130)
[팁] JUnit 에러 : java.lang.ExceptionInInitializerError
JUnit을 적용하기 시작하면서 제일 처음 마주한 에러였다. 야심 차게 TDD 적용을 꿈꾸며 @Test 애노테이션을 넣고 실행했는데 다음과 같은 에러가 발생했다. 에러 로그 java.lang.ExceptionInInitializerError a
kyome.tistory.com
참고: https://galid1.tistory.com/476
Test - Junit이란?
Junit 이란 Junit 이란? Junit이란 Java의 단위 테스팅(Unit Testing) 도구이다. 단 하나의 jar 파일로 되어 있다. Testing 결과를 단순히 문서로 남기는 것이 아니라 Test Class 를 그대로 남김으로써 추 후 개발.
galid1.tistory.com
https://spongeb0b.tistory.com/188
The import org.springframework.boot.test cannot be resolved
테스트케이스를 작성하던 도중에 에러를 만났다. @Runwith(SpringRunner.class)는 pom.xml에 dependency를 추가해주니 바로 해결됬지만. (이건 검색하면 바로 뜬다.) 어째 @SpringBootTest는 에러가 사라지지 않았.
spongeb0b.tistory.com
내가 보려고 기록 : https://ojava.tistory.com/58
eclipse에서 JUnit을 이용한 테스트 수행
JUnit Cookbook을 분명히 보고왔건만 맛보기만 해주는 내용이라 cookbook인 것이 확실하다. 직접 eclipse에 JUnit을 도입해서 간단한 테스트를 수행하면 향후 응용에 도움이 될 수 있을 것으로 생각되므
ojava.tistory.com