작성
·
281
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
로 변경해보시면 좋을 것 같습니다!!
감사합니다!!! 🙇🙇