Open MateuszMysliwiec opened 5 years ago
Hi @MateuszMysliwiec thanks for the report.
I've tried to reproduce this but it works fine for me, so here's a few questions that would help diagnosing it:
@Rule public FixtureRule fr = FixtureRule.initFixtures()
or FixtureAnnotations.initFixtures(this);
which will initialise the @Fixture
fields?import com.flextrade.jfixture.annotations.Fixture;
import com.flextrade.jfixture.annotations.Range;
long
instead of int
?Thanks!
Hi @richkeenan, thank you for response.
I am using latest version of JFixture, and looks like I have misunderstood the "Cheat Sheet" guide because I am not using any of those mentioned here:
Are you running @Rule public FixtureRule fr = FixtureRule.initFixtures() or FixtureAnnotations.initFixtures(this); which will initialise the @Fixture fields?
Here is my workflow:
I am doing it this way:
JFixture fixutre = new JFixture();
SomeEntity siteRequirement = fixture.create(SomeEntity.class);
And that is all, now inside SomeEntity class, I wanted to specify ranges for some variables, using add-notations specified in first post, answering your question, I checked and I am using correct imports, so it must be probably lack of @Rule you mentioned, but I still do not understand where shall I put it in my case, thank you again and sorry if I missed something.
Assuming SomeEntity
is a production class, it shouldn't have @Fixture
annotations in it. Remove jfixture
dependency from production, and keep it only for test source set.
The @Fixture
annotation is only processed by the rule or initFixtures
.
The way you're creating your fixture object works without the annotation, but creates a full-range value as you observed.
Sometimes if you want a specific value you need to set it manually:
SomeEntity siteRequirement = fixture.create(SomeEntity.class);
siteRequirement.minNoOfFirstAidersRequiredInTeam = fixture.create().inRange(int.class, 1, 10)
If you want to create multiple of these objects but don't want to manually configure all the time, you can use fixture.customize().intercept(SomeEntity.class, ...)
(or transform
) to change the auto-generated object.
Hello, I am trying to specify range to int:
But still, returned int value is not in range 1-10, any help would be appreciated, thank you!