본문 바로가기

Spring/Spring Framework

[에러]Class<SpringJUnit4ClassRunner> cannot be resolved to a type- 모듈 추가

 

JUnit으로 스프링 테스트를 하기 위해 설정 중 오류

JUnit 설정을 항상 템플릿으로 만들어 사용 하다 보니 잊고 있었다.

모듈을 추가 하지 않았다는 것을

 

pom.xml에 모듈 추가하면 해결된다.

1
2
3
4
5
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-test</artifactId>
        <version>${org.springframework-version}</version>
    </dependency>
 

spring-test는 @RunWith와 @ContextConfiguration등 Spring Framework에서 어노테이션을 이용한 테스트를 가능하게 해준다.


테스트에 필요한 다른 모듈도 추가 되어 있는지 확인하자

1
2
3
4
5
6
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.7</version>
            <scope>test</scope>
        </dependency>
  • JUnit은 java에서 단위 테스트를 가능하게 해준다.
1
2
3
4
5
6
        <dependency>
            <groupId>org.hamcrest</groupId>
            <artifactId>hamcrest-library</artifactId>
            <version>1.3</version>
            <scope>test</scope>
        </dependency>      
  • Hamcrest 프레임워크를 이용하면 JUnit을 사용할 때 가독성과 코드의 조건을 쉽게 확인 가능하다.