我正在使用 JunitJupiter 进行单元测试。现在我不知道如何检查列表的顺序。
代码:
@Test
@DisplayName("Should be in ascending order")
void sortAscending() {
List<List<AccountlinevaluesEntity>> finalList = monthlySuSa;
for (List<AccountlinevaluesEntity> list : finalList) {
list.sort(Comparator.comparing(AccountlinevaluesEntity::getAccountNumber));
assert(list, ...........);
}
}
我对单元测试还很陌生,我搜索了很多,但我不知道如何去做。
那么,有没有办法用 jUnitJupiter 来做到这一点,或者还有其他方法吗?
最佳答案
尝试
assertThat(list, Matchers.contains("your", "items", "in", "order")
来自 JavaDoc
Creates a matcher for {@link Iterable}s that matches when a single pass over the examined {@link Iterable} yields a series of items, each logically equal to the corresponding item in the specified items. For a positive match, the examined iterable must be of the same length as the number of specified items.
关于java - 有没有办法用 jUnit Jupiter 测试列表/集合的顺序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59286146/