Java 如何为JPA存储库编写集成测试
我正在尝试为定义为的JPA存储库进行集成测试Java 如何为JPA存储库编写集成测试,java,spring,spring-data-jpa,spring-test,Java,Spring,Spring Data Jpa,Spring Test,我正在尝试为定义为的JPA存储库进行集成测试 @Repository public interface TaskRepository extends JpaRepository<Task, Long>, JpaSpecificationExecutor<Task> { @Query("SELECT r from Task r where r.user.id = :userId AND r.date >= :startDate AND r.date
@Repository
public interface TaskRepository extends JpaRepository<Task, Long>, JpaSpecificationExecutor<Task> {
@Query("SELECT r from Task r where r.user.id = :userId AND r.date >= :startDate AND r.date <= :endDate")
List<Task> getTasksBetweenDates(@Param("userId") long userId, @Param("startDate") LocalDate startDate, @Param("endDate") LocalDate endDate);
}
在我的项目中,我们使用了SpringBoot(v2.4.3)。以下代码在测试JPA存储库时运行良好
@SpringBootTest
公共类人员安置测试{
@自动连线
个人知识库;
...
是否可以显示添加了完整堆栈跟踪错误消息的错误消息。请检查并链接它应有帮助。
@ExtendWith(SpringExtension.class)
@DataJpaTest
public class TaskRepositoryIntegrationTest {
@Autowired
private TaskRepository taskRepository;
<test methods>
}
java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=...) with your test