2
스프링 주석에 문제가 있습니다. 모두 내가 원하는 공통적 인 설정과 함께 하나의 주석에 필요한 모든 테스트 주석을 잡아서 스프링 컨텍스트가 시작될 때 널 포인터 예외를 얻는다. (bean을 autowire 할 수 없다.) 그러나 모든 주석 클래스를 따로 따로 사용하면 모든 것이 잘 동작한다. 디자인에 의해 사용자 정의 주석 @ContextConfiguration을 결합 할 수 있기 때문에 내가 @MyTestAnnotations의 구성을 사용하려면별도의 주석으로 구성 주석을 테스트하십시오.
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD,ElementType.TYPE})
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@ContextConfiguration(classes = { JPAConfig.class, AOPConfiguration.class })
@TestExecutionListeners({ DependencyInjectionTestExecutionListener.class, TransactionalTestExecutionListener.class })
public @interface MyTestAnnotations {
}
그리고 테스트 케이스가
@MyTestAnnotations
public class AspectTest {
@Autowired
PagingAndSortingBookRepository pagingAndSortingRepo;
@Autowired
SmartLoggerAspect smartLoggerAspect;
JoinPoint joinPoint;
// other methods
@Test
public void pagingTest(){
// line below throws nullPointerException
pagingAndSortingRepo.findAll(new PageRequest(1, 1));
}
}
같은 것을 사용할 수 있어야합니다. Thans! –
나는이 사람이 왜 그런 일을하는지 모릅니다 : https://youtu.be/5tgkxGEvK4U?t=2228 –
@ PrzemysławSienkiewicz 예. 나도 궁금해하게 비트. 나는 그것이 실제로 작동하는지 여부에 대해 확실하지 않습니다. 어쨌든 공유해 주셔서 감사합니다. – kuhajeyan