티스토리 뷰

starter-test 의존성도 잘 추가가 되어있고, 테스트 코드도 test/java 경로에 잘 들어가 있는데,

 

IntelliJ에서 아래 테스트 코드를 수행하면 junit 패키지를 찾지 못한다는 에러가 발생하는 경우가 있습니다.

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.test.context.junit4.SpringRunner;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.*;

@RunWith(SpringRunner.class)
@DataJpaTest
public class PostRepositoryTest {

    @Autowired
    PostRepository postRepository;

    @Test
    public void crudRepository(){
        .....
    }
}
error: package org.junit does not exist
import org.junit.Test;
                ^
                
error: package org.junit.runner does not exist
import org.junit.runner.RunWith;
                       ^
                       
error: cannot find symbol
@RunWith(SpringRunner.class)
 ^
  symbol: class RunWith

 

IntelliJ의 Preferences > Build, Execution, Deployment > Build Tools > Grade 창으로 이동을 하면

 

Build and run using, Run test using 옵션이 모두 Gradle로 되어 있는데 이를 IntellliJ로 변경하면 더 이상 junit 관련 오류가 발생하지 않습니다.

변경 전

 

 

 

변경 후

 

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
글 보관함