Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
Tags
- designpattern
- junit
- pscp
- 자료구조
- mycp
- 10844
- @Spring
- gradle
- 여러인수
- decorator
- createQuery
- setParameter
- C
- java
- Linux
- 전치행렬 #C
- springboot
- 점세개
- 자바
- 쉬운 계단 수
- 디자인패턴
- 숫자야구
- NamedParameterNotBound
- BubbleSorting
- 백준
- @NotEmpty
- Spring
- @ModelAttribute
- 데코레이터패턴
- 10951
Archives
- Today
- Total
...
Junit의 @BeforeEach 이 실행 안 됨 오류 본문
package hello.core.order;
import hello.core.AppConfig;
import hello.core.member.Grade;
import hello.core.member.Member;
import hello.core.member.MemberService;
import org.assertj.core.api.Assertions;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
public class OrderServiceTest {
MemberService memberService;
OrderService orderService;
@BeforeEach
public void beforeEach(){
AppConfig appConfig = new AppConfig();
memberService = appConfig.memberService();
orderService = appConfig.orderService();
}
@Test
public void createOrder(){
long memberId=1L;
Member member = new Member(memberId,"memberA", Grade.VIP);
memberService.join(member);
Order order = orderService.createOrder(memberId,"itemA",10000);
Assertions.assertThat(order.getDiscountPrice()).isEqualTo(1000);
}
}
위와 같은 코드에서, @BeforeEach부분의 memberService와 orderService의 초기화가 진행되지 않아 NPE(Null Pointer Exception)이 발생하였다.
package hello.core.order;
import hello.core.AppConfig;
import hello.core.member.Grade;
import hello.core.member.Member;
import hello.core.member.MemberService;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.BeforeEach;
Test 어노테이션을 불러오는 import 부분을
import org.junit.Test 에서
import org.junit.jupiter.api.Test
로 변경해주었더니 문제가 해결 되었다.
'이것저것 > 오류 해결' 카테고리의 다른 글
H2 연결 에러가 발생하였을 때 해결 방법 (0) | 2022.03.26 |
---|---|
[MAVEN/JAVA11 JPA 이용시 에러 해결]ClassNotFoundException (0) | 2022.03.26 |
Error : Gradle + Junit 어노테이션이 import 되지 않을 때 (0) | 2022.02.23 |
Gradle import할 때 발생하는 오류 해결 (Unable to find method) (0) | 2022.01.10 |
[C언어] 만약 visual studio에서 NULL이 인식되지 않는다면! (0) | 2021.11.13 |
Comments