您好,我目前正在尝试为服务定义测试,该测试应该在特定实体上执行操作。 问题是它总是在运行测试之前失败。
项目设置: 环境
依赖关系(等级)
> id | name | Total
> -: | :---- | ----:
> 1 | Test1 | 3
> 2 | Test2 | 1
> 3 | Test3 | 2
测试代码:
dependencies {
implementation 'io.quarkus:quarkus-jdbc-postgresql'
implementation 'io.quarkus:quarkus-liquibase'
implementation 'io.quarkus:quarkus-hibernate-orm-panache'
implementation 'io.quarkus:quarkus-kotlin'
implementation 'io.quarkus:quarkus-smallrye-openapi'
implementation 'io.quarkus:quarkus-resteasy-jsonb'
implementation 'io.quarkus:quarkus-hibernate-validator'
implementation enforcedPlatform("${quarkusPlatformGroupId}:${quarkusPlatformArtifactId}:${quarkusPlatformVersion}")
implementation 'io.quarkus:quarkus-resteasy'
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8'
testImplementation 'io.quarkus:quarkus-jdbc-h2'
testImplementation 'io.quarkus:quarkus-junit5'
testImplementation 'io.quarkus:quarkus-panache-mock'
testImplementation 'io.rest-assured:kotlin-extensions'
testImplementation 'org.mockito:mockito-all:1.10.19'
}
当我尝试运行此测试时,它只会在控制台中返回:
@QuarkusTest
public class CategoryServiceImplTest
{
@Inject
CategoryServiceImpl categoryService;
@Test
void should_get_page_of_3_categories()
{
// given
PanacheMock.mock(Category.class);
final List<Category> categories = new ArrayList<>();
for (int i = 0; i < 5; i++)
{
categories.add(ApplicationTestUtils.generateCategory());
}
when(Category.find(any(), Sort.by("name"))).thenReturn(mock(PanacheQuery.class));
when(Category.count()).thenReturn(30L);
// when
final ListModel<Category> result = categoryService.getList(3, 0);
// then
assertEquals(result.getListInfo().getLengthTotal(), categories.size());
}
}