• 카테고리

    질문 & 답변
  • 세부 분야

    백엔드

  • 해결 여부

    미해결

@BeforeEach method 'public static final void com.group.libraryapp.calculator.JunitTest.beforeAll()' must not be static.

23.01.17 14:01 작성 조회수 216

1

package com.group.libraryapp.calculator

import org.junit.jupiter.api.AfterAll
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test

class JunitTest {

    companion object {
        @BeforeEach
        @JvmStatic
        fun beforeAll() {
            println("모든 테스트 시작 전 ")
        }

        @AfterAll
        @JvmStatic
        fun afterAll() {
            println("모든 테스트 시작 후")

        }
    }

    @BeforeEach
    fun beforeEach() {
        println("각 테스트 시작 전")
    }

    @AfterEach
    fun afterEach() {
        println("각 테스트 시작 후 ")
    }

    @Test
    fun test1() {
        println("테스트 1")
    }

    @Test
    fun test2() {
        println("테스트 2")
    }

}

이렇게 하고 실행했는대, 
@BeforeEach method 'public static final void com.group.libraryapp.calculator.JunitTest.beforeAll()' must not be static.

이런 에러가 나와요 ㅠ

답변 1

답변을 작성해보세요.

1

안녕하세요, kimminji0511님!! 질문해주셔서 감사드립니다!! 🙏

확인해보니, companion object 안에 @BeforeAll 대신 @BeforeEach 를 붙이신 것 같습니다!!


companion object 안에 들어가야 하는 어노테이션으로는

  • @BeforeAll

  • @AfrterAll

이 있고, All로 끝나는게 특징이죠!

 

일반 클래스 안에 들어가는 어노테이션으로는

  • @BeforeEach

  • @AfterEach

가 있습니다!

 

companion object 안에 있는 @BeforeAll@BeforeEach 로 변경해보시면 좋을 것 같습니다!!

감사합니다!!! 🙇🙇