我正在使用带有 Mockito 框架的 spring-boot 测试来测试我的应用程序。存储库类之一 EntityManager 作为参考。
我的班级如下所示。
@Repository
@Transactional
@Slf4j
public class SomeRepositoryService {
@PersistenceContext
private EntityManager entityManager;
public List<Run> findBySearchCriteria(String searchCriteria,Integer
offset,Integer limit,Integer userId) {
//code
}
}
测试类看起来像:
@RunWith(SpringRunner.class)
@SpringBootTest
public class RunRepositoryServiceTests {
@MockBean
EntityManager entityManager;
@Autowired
private RunRepositoryService runRepositoryService;
@Test
public void testFindBySearchCriteria() {
//code to test
}
}
当我运行这个时,我得到
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.jpa.repository.support.DefaultJpaContext]: Constructor threw exception; nested exception is java.lang.NullPointerException
Caused by: java.lang.NullPointerException: null
at org.springframework.data.jpa.repository.support.DefaultJpaContext.<init>(DefaultJpaContext.java:53) ~[spring-data-jpa-2.0.9.RELEASE.jar:2.0.9.RELEASE]
谁能让我知道如何测试或解决这个问题?
波斯汪
尚方宝剑之说
慕码人8056858
相关分类