I am curious if in the Kotlin, in the parameterized tests in Junit5, i can use the method outside the class as the @MethodSource.
I know about 2 ways to use @MethodSource in Kotlin - companion object and @TestInstance(TestInstance.Lifecycle.PER_CLASS). I wonder if it can be done in a different way, for example by declaring a method outside the class and using some annotation? I tried to do it this way, but it does not work, I wonder if something similar can be done.
class GenerationStatusTest {
@ParameterizedTest
@MethodSource("provideStatusesToTest")
internal fun shouldStatusesHaveExpectedAbilities(generationStatus: GenerationStatus, assertions:(GenerationStatus)->Unit) {
assertions(generationStatus)
}
}
fun provideStatusesToTest(): Stream<Arguments> {
return Stream.of(
Arguments.of(WAITING, canDoNothing),
Arguments.of(PROCESSING, canDoNothing)
)
}
org.junit.platform.commons.JUnitException: Could not find factory method [provideStatusesToTest] in class [com.test.enums.GenerationStatusTest]
at org.junit.jupiter.params.provider.MethodArgumentsProvider.lambda$getMethod$4(MethodArgumentsProvider.java:83)