Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add kotlin Sequence support for @TestFactory annotated methods #3376

Open
2 tasks done
hanszt opened this issue Jul 2, 2023 · 2 comments · May be fixed by #3377
Open
2 tasks done

Add kotlin Sequence support for @TestFactory annotated methods #3376

hanszt opened this issue Jul 2, 2023 · 2 comments · May be fixed by #3377

Comments

@hanszt
Copy link

hanszt commented Jul 2, 2023

It would be nice if you could write something like this in kotlin when working with junit5

        @TestFactory
        fun `dynamic tests returned as Kotlin sequence`() = generateSequence(0) { it + 2 }
                .map { dynamicTest("$it should be even") { assertTrue(it % 2 == 0) } }
                .take(10)

Now you have to add .toIterable() as extra line to make it work with junit5.

Deliverables

  • Adding support for converting iterator providing classes to a stream in org.junit.platform.commons.util.CollectionUtils.
  • Adding support for converting spliterator prodiving classes to a stream in org.junit.platform.commons.util.CollectionUtils.

The kotlin Sequence class is an example of an iterator providing class. But it is not an Iterable. That's why it does not work as returntype for for example @testfactory annotated methods at the moment.

A benefit of adding this at this low level is that, kotlin Sequences, or any other Iterator or Spliterator providing class can now also be used in other junit5 methods where an object from an annotated method needs to be converted to a stream.

I have an implementation for it ready. see:

Suggestion

All tests still pass.

I would like to contribute to junit5 and make a pull request for this branch but I don't have push permission yet for a feature branch in the junit5 project.

Could you please be so kind to take a look at the suggestion I provided?

Thanks in advance! I'm awaiting your response :)

@hanszt hanszt changed the title Add kotlin sequence support for @testfactory methods Add kotlin Sequence support for @TestFactory annotated methods Jul 2, 2023
@hanszt hanszt linked a pull request Jul 2, 2023 that will close this issue
6 tasks
@marcphilipp marcphilipp linked a pull request Jul 7, 2023 that will close this issue
6 tasks
@marcphilipp
Copy link
Member

Team decision: Add convention-based conversion to Stream that looks for methods called iterator that return Iterator.

@hanszt
Copy link
Author

hanszt commented Jul 19, 2023

Thanks for the feedback. I implemented the requested changes in this pullrequest

@marcphilipp marcphilipp modified the milestones: 5.11 M1, 5.12 Feb 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment