【问题标题】:kotlin Springboot mockito integration test - EntityMangerkotlin Spring Boot mockito 集成测试 - EntityManager
【发布时间】:2022-01-27 04:51:34
【问题描述】:

如何在springboot mockito集成测试中模拟EntityManger

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
    classes = [EntityManager::class],
    properties = [
    "spring.datasource.url=jdbc:mysql://localhost:3306/db"
]

我应该将 EntityManager 放在类中还是应该以不同的方式模拟它

【问题讨论】:

  • 我有类似的问题,我像你一样在 SpringBootTest 类中添加了这个类,还添加了 @MockBean lateinit var someClass: Class

标签: spring-boot kotlin mockito integration hibernate-entitymanager


【解决方案1】:

我从类中删除了 EntityManager,但我在 mocke 的类中忘记了它,因为我在 JPA 层中使用了 JdbcAggregateOperations。

我的集成测试新配置就是这样

    @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
    classes = [],
    properties = "spring.datasource.url=jdbc:mysql://localhost:3306/db"])
 class DemoApplicationTests(@Autowired val restTemplate: TestRestTemplate,
                       @Autowired private val repository: UserRepository) {`

谢谢

【讨论】:

    猜你喜欢
    • 2020-07-24
    • 2020-09-17
    • 2017-03-17
    • 2020-02-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-20
    • 2020-04-24
    相关资源
    最近更新 更多