Junit5: Add assertion methods to handle iterators and streams

Created on 5 Oct 2016  路  7Comments  路  Source: junit-team/junit5

With the merging of https://github.com/junit-team/junit5/pull/294 into master, I think it's a good time now to discuss whether deep equality assertion methods for iterators and streams, like assert(Iterator|Stream)Equals, should be introduced.

In my opinion, since assertIterableEquals exists now, it would be a silly oversight to not have support for the other two enumera(ble|tor) concepts as well.

I also think that a number of users would expect such assertion methods to exist, as @TestFactory methods currently support returning Iterables, Iterators and Streams of DynamicTests.

What does everyone think of this?

Most helpful comment

Personally, I think we should refrain from adding too many assertions. Both Iterators and Stream are easily converted into a Collection or Iterable in order to use the existing assertion methods.

@junit-team/junit-lambda What do you guys think?

All 7 comments

FYI I'd be happy to implement this if it's worthwhile and noone else has the time to do so.

Personally, I think we should refrain from adding too many assertions. Both Iterators and Stream are easily converted into a Collection or Iterable in order to use the existing assertion methods.

@junit-team/junit-lambda What do you guys think?

Simplicity is preferable. There should be one and only one option for each type. The more options - the more cognitive load, the more tiny mistakes. In addition we will be fuelling years of future debate over which one to use when :-)

Cheers
Mark

Personally, I think we should refrain from adding too many assertions. Both Iterators and Stream are easily converted into a Collection or Iterable in order to use the existing assertion methods.

@junit-team/junit-lambda What do you guys think?

I agree.

@mlevison The assertions included in Jupiter are only meant as a starting point. You almost always want better assertions as provided by Hamcrest or AssertJ.

All the arguments given here against my proposal actually sound very reasonable to me! In light of those arguments, I'd be happy to this issue to be closed if no one has any objections. :)

Alright, I'll close it for now.

Was this page helpful?
0 / 5 - 0 ratings