inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

테스트가 안됩니다 @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=...) with your test

해결된 질문

183

김주현

작성한 질문수 1

0

안녕하세요 강의 잘 듣고 있습니다. 실전 Querydsl에서 설정 후 테스트 중

테스트가 잘 안되서 질문 드립니다.

package study.querydsl;
import com.querydsl.jpa.impl.JPAQueryFactory;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.Commit;
import org.springframework.transaction.annotation.Transactional;
import study.querydsl.entity.Hello;
import study.querydsl.entity.QHello;
import javax.persistence.EntityManager;

@SpringBootTest
@Transactional
class QuerydslApplicationTests {
   @Autowired
   EntityManager em;

   @Test
   void contextLoads() {
      Hello hello = new Hello();
      em.persist(hello);
      JPAQueryFactory query = new JPAQueryFactory(em); 
      QHello qHello = QHello.hello; //Querydsl Q타입 동작 확인
      Hello result = query
            .selectFrom(qHello)
            .fetchOne();
      Assertions.assertThat(result).isEqualTo(hello);
//lombok 동작 확인 (hello.getId())
      Assertions.assertThat(result.getId()).isEqualTo(hello.getId());
   }
}

 

--오류메세지--

java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=...) with your test

at org.springframework.util.Assert.state(Assert.java:76)

 

테스트 코드와 실제 코드 디렉토리때문인가 해서 @SpringBootTest(classes=Hello.class) 로 실행하면

em bean관련 오류코드가 뜹니다..

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'study.querydsl.QuerydslApplicationTests': Unsatisfied dependency expressed through field 'em'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'javax.persistence.EntityManager' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

 

답변 0

강의 수강 후 포트폴리오 준비 방향에 대해 조언 부탁드립니다.

2

38

1

쿠버네티스 어나더 클래스-Sprint 1, 2 강의 관련 질문이있습니다.

1

34

1

갑자기 stock_prediction은 어디서 발생한건가요?

1

49

2

FRED API

1

44

1