How to JUnit test that two List contain the same elements in the same order?

前端 未结 7 1594
星月不相逢
星月不相逢 2021-02-01 00:39

Context

I am writing a simple JUnit test for the MyObject class.

A MyObject can be created from a static factory met

7条回答
  •  旧时难觅i
    2021-02-01 00:47

    For excellent code-readability, Fest Assertions has nice support for asserting lists

    So in this case, something like:

    Assertions.assertThat(returnedComponents).containsExactly("One", "Two", "Three");
    

    Or make the expected list to an array, but I prefer the above approach because it's more clear.

    Assertions.assertThat(returnedComponents).containsExactly(argumentComponents.toArray());
    

提交回复
热议问题