Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop generating random values #863

Open
praveenfun2 opened this issue Jan 9, 2024 · 3 comments
Open

Stop generating random values #863

praveenfun2 opened this issue Jan 9, 2024 · 3 comments
Labels
question Further information is requested

Comments

@praveenfun2
Copy link

Describe your question

Is there a way by which we can disable prepopulating the fields with random values.

@praveenfun2 praveenfun2 added the question Further information is requested label Jan 9, 2024
@seongahjo
Copy link
Contributor

seongahjo commented Jan 9, 2024

@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.

  1. 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.
  2. You can use pushArbitraryIntrospector option
  3. You can use pushPropertyGenerator option to remove the properties that are not random values. But in this case, you can not use set API.

@praveenfun2
Copy link
Author

praveenfun2 commented Jan 9, 2024

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.

@seongahjo
Copy link
Contributor

seongahjo commented Jan 10, 2024

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants