Closed praveenfun2 closed 1 month ago
@praveenfun2 Hello, it would be great with a detailed example. Is it for a specific test case or all test cases?
There are several ways to disable pre-population. Here are some common ways you can handle this issue.
set
API in ArbitraryBuilder would prevent the generation of a random value.
It will work in all test cases if you use this API in register
option.
If it is too complex to generate, then use set
API with Values.just
.pushArbitraryIntrospector
optionpushPropertyGenerator
option to remove the properties that are not random values. But in this case, you can not use set
API.So I want to disable this feature altogether, as if it was not even present. I have an existing setup of test cases where we don't populate the values randomly. We populate the values by hardcoding it. So the values which are not harcoded, I want them to be null.
@praveenfun2
If so, you can use defaultNullInjectGenerator
option.
FixtureMonkey nullGenerateFixtureMonkey = FixtureMonkey.builder()
.defaultNullInjectGenerator(
new DefaultNullInjectGenerator(
1.0d,
false,
false,
false,
Collections.emptySet(),
Collections.emptySet()
)
)
.build();
nullGenerateFixtureMonkey
will generate all properties as null if no customization APIs are used.
Or You can use your existing test setup just as below.
fixtureMonkey.giveMeBuilder(YourExistingTestObject)
.sample()
FixtureMonkey instance will generate an object exactly like your existing test object, without populating it with random values. You can also customize it just like any other instance Fixture Monkey generates.
Let me know if any more questions!
Describe your question
Is there a way by which we can disable prepopulating the fields with random values.