티스토리 뷰

반응형
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = WebApplication.class)
public class SwgDatabaseTest {

    @Autowired
    private UserService userService;

    @Test
    public void test(){
        System.out.println("1234");
    }
}
  • 위와 같이 테스트 코드를 작성하고 돌려보니 아래 에러가 출력되었다.
11월 24, 2020 12:46:11 오후 org.junit.vintage.engine.descriptor.RunnerTestDescriptor warnAboutUnfilterableRunner
경고: Runner org.junit.internal.runners.ErrorReportingRunner (used on class SwgDatabaseTest) does not support filtering and will therefore be run completely.

org.junit.runners.model.InvalidTestClassError: Invalid test class 'SwgDatabaseTest':
  1. No runnable methods
    at org.junit.runners.ParentRunner.validate(ParentRunner.java:525)
    at org.junit.runners.ParentRunner.<init>(ParentRunner.java:92)
  • 구글링 해보니, junit4와 junit5에서 제공되는 클래스를 혼용해서 나온 에러였다ㅠ

  • junit5에서는 @RunWith 어노테이션을 지원하지 않는다. 대신 @ExtendWith 지원한다.

    • 따라서 org.junit.jupiter.api.Test 을 사용할 경우에는 @ExtendWith를 사용해줘야한다.
  • junit4를 사용하려면 org.junit.jupiter.api.Test -> import org.junit.Test; 으로 변경해주면 된다.

 

  • junit5 기준으로 수정된 코드
import com.swg.WebApplication;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit.jupiter.SpringExtension;

import java.util.Date;

@ExtendWith(SpringExtension.class)
@SpringBootTest(classes = WebApplication.class)
public class SwgDatabaseTest {

    @Test
    public void test() {
        System.out.println("test");
    }
}
  • junit4 기준으로 수정된 코드
import com.swg.WebApplication;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit.jupiter.SpringExtension;

import java.util.Date;

@ExtendWith(SpringExtension.class)
@SpringBootTest(classes = WebApplication.class)
public class SwgDatabaseTest {

    @Test
    public void test() {
        System.out.println("test");
    }
}
  • junit5
import com.swg.WebApplication;


import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.Date;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = WebApplication.class)
public class SwgDatabaseTest {

    @Test
    public void test() {
        System.out.println("test");
    }
}
반응형
댓글
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/09   »
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
글 보관함