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

Document @MethodSource as use case for @TestInstance per-class lifecycle #3219

Merged
merged 2 commits into from
Apr 2, 2023
Merged

Document @MethodSource as use case for @TestInstance per-class lifecycle #3219

merged 2 commits into from
Apr 2, 2023

Conversation

mahozad
Copy link
Contributor

@mahozad mahozad commented Mar 31, 2023

Overview

Related Stack Overflow post: What use is @TestInstance annotation in JUnit 5?

Add another use case for TestInstace.PER_CLASS in Kotlin, which is, using regular simple class methods as the method factory for @MethodSource (which is used for parameterized tests):

@ParameterizedTest
@MethodSource("generateStrings")
fun `Test strings`(argument: String) {
    check(argument.isNotEmpty())
}

private fun generateStrings() = listOf(
    "java",
    "kotlin"
)

I hereby agree to the terms of the JUnit Contributor License Agreement.


Add another use case for TestInstace.PER_CLASS in Kotlin, namely, using regular simple class methods as the argument producer for @MethodSource (which is used for parameterized tests)
Copy link
Member

@sbrannen sbrannen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update the User Guide in a similar fashion.

For tests authored using Kotlin programming language
@mahozad mahozad requested a review from sbrannen April 1, 2023 16:27
@sbrannen sbrannen marked this pull request as ready for review April 1, 2023 16:40
@sbrannen sbrannen changed the title Update @TestInstance javadoc with a new use case Document @MethodSource as use case for @TestInstance per-class lifecycle Apr 2, 2023
Copy link
Member

@sbrannen sbrannen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for updating the user guide as well.

@sbrannen sbrannen merged commit a5b642b into junit-team:main Apr 2, 2023
@sbrannen
Copy link
Member

sbrannen commented Apr 2, 2023

This has been merged into main.

Thanks

@mahozad
Copy link
Contributor Author

mahozad commented Apr 2, 2023

Thanks for merging.

yhkuo41 pushed a commit to yhkuo41/junit5 that referenced this pull request Apr 19, 2023
…fecycle

This commit documents another use case for TestInstace.PER_CLASS in Kotlin,
namely, using a regular simple class method as a factory method for @MethodSource
(which is used for parameterized tests).

Closes: junit-team#3219
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants