Closed veluxer62 closed 1 year ago
When I add Map
and List
type parameter, There are empty value in the test parameter data.
Is there any problems in my code?
I had similar problems when I wrote a Kotlin extension function. I had to use fixture.collections()
to create them. Not sure why though.
@TWiStErRob
When worte Map
and List
type variable in class. fixture generated data as I expected.
See 22 to 31 lines in FixtureResolverTest.java
.
Yeah, the difference is having it as part of another Class (field, ctor param); that works fine, but directly fixture.create(new SpecimenType<List<String>>() {})
doesn't work.
I've had the same issue with collections - ended up using Kotlin generator functions, didn't look much into it and chalked it up to type erasure.
While this is a good added feature (parameterised @Fixture
), I'm just wondering why not just use member variables with @Fixture
? Is it for readability? (genuinely asking, not being a troll :) )
@rses it's just how JUnit 5 works. In most test classes individual tests don't use all of the fixtures, and also they also create more in local variables. There's a reason while injected parameters become a thing in JUnit 5.
Do you mean operator invoke by "generator"?
The FixtureResolver functions to generate function parameter data for test.
I referred here: