java - 有没有办法用 jUnit Jupiter 测试列表/集合的顺序?

标签 java list junit-jupiter

我正在使用 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/

相关文章:

java - 使用变量参数在没有 ArrayList 的情况下查找数字的乘积?

java - java.lang.IllegalArgumentException : Not a managed type 的问题

javascript - 隐藏和显示列表和子列表

java - 在 Java 中从 ArrayList 打印不同的对象数据

java - IntelliJ + JUnit 5(木星)

kotlin - 如何在Kotlin中测试使用readline(System .`in`)的代码?

使用 langdetect 进行 Java 语言检测 - 如何加载配置文件?

java - gson.fromJson StackOverFlowError

Python组合和产品

java - 如何使用 mockito 测试运行异步线程的方法