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)
참고: https://galid1.tistory.com/476
https://spongeb0b.tistory.com/188
내가 보려고 기록 : https://ojava.tistory.com/58