我的目标是测试存储库接口的方法。当我运行这个时,我有一些错误,但是我修复了它们(希望如此)。但我不明白下面的一个:完整的错误堆栈
我不知道这个错误的原因是什么,因为我从不使用 @BootstrapWith
在我的测试课上。
这是我的测试课:
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@SpringBootTest
@DataJpaTest
class DepartmentRepositoryTest {
@Autowired
private lateinit var entityManager: TestEntityManager
private lateinit var departmentRepository: DepartmentRepository
@Test
fun runFindAllByMembersContainsForNormalValuesShouldBeTrue() {
val departmentAddress = DepartmentAddress("Musterstraße 1", "0", "Musterstadt", "Musterland")
val cardLimits: MutableMap<JobType, Int> = mutableMapOf(Pair(JobType.EXPRESS, 1))
val members: HashSet<Long> = mutableSetOf<Long>(1) as HashSet<Long>
val department = Department("Test-Department", Cluster.CENTER, departmentAddress, cardLimits, true, PaymentMethods.CARD_PAYMENT_ONLY, "", "", members)
entityManager.persist(department)
entityManager.flush()
val userId = 1.toLong()
val departments = departmentRepository.findAllByMembersContains(userId)
Assertions.assertThat(departments).isEqualTo(arrayOf(department))
}
}
我不使用 @Autowire
对于 departmentRepository
,因为我会得到一个错误,这个接口中没有bean。
暂无答案!
目前还没有任何答案,快来回答吧!