Hey peepz, how are you?
I have a question regarding Tests,
@Nested
,
inner
classes,
ParametrizedTests + MethodSource
I have the following
Copy code
class MyServiceTest {
data class TestData(...)
@Nested
inner class MyServiceSpecific{
private fun prepareTestData() = Stream.of(...)
@ParameterizedTest
@MethodSource("prepareTestData")
fun `GIVEN this example WHEN executing test THEN should run`(data: Testdata) {
// EVERYTHING I WANT TO TEST
}
}
}
With this structure I get the following error
Copy code
Cannot invoke non-static method [private final java.util.stream.Stream... on a null target.
How can I gave all this working, I am missing a glue probably
Daniel Branco
09/12/2021, 5:45 PM
I found the solution I need to tell JUnit that needs to create my inner class using
Copy code
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
But I thought that Nested annotation were doing that already from the enclosing class
b
Benoît Liessens
09/13/2021, 3:36 AM
Have you tried removing the
inner
keyword?
d
Daniel Branco
09/13/2021, 8:13 AM
According to @Nested documentation says that it should be a non static class, and inner do that for you