问题描述
您好,我目前正在尝试为服务定义测试,该测试应该在特定实体上执行操作。 问题是它总是在运行测试之前失败。
项目设置: 环境
- macOS 10.16
- Java 11 项目
- 构建工具:Gradle
依赖关系(等级)
> 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());
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)