fixture-monkey
fixture-monkey copied to clipboard
feat: log Fixture Monkey seed on test failure
Summary
#990
(Optional): Description
- New
FixtureMonkeySeedExtensionClass
- FixtureMonkeySeedExtension implements AfterTestExecutionCallback
- This extension is responsible for capturing and logging the seed used in the test when it fails, provided the test method is annotated with @Seed
afterTestExecutionMethod
- The method checks if the @Seed annotation is present on the test method. it retrieves the current random seed using Randoms.currentSeed() and stores it in SEED_HOLDER.
- If the test fails (context.getExecutionException().isPresent()), the seed is logged along with the test method name.
@ExtendWith(FixtureMonkeySeedExtension.class)
public class MyTest {
@Seed
@Test
void myTest() {
}
}
How Has This Been Tested?
Is the Document updated?
Currently, the FixtureMonkeyBuilder does not have a getSeed method to retrieve the seed value. The FixtureMonkeyBuilder class should not be modified.
We intend to get and set the seed in Randoms in develop.
But, the client sets the seed exposed by FixtureMonkeyBuilder, which is not what we normally do.
As a result, the client is unaware of the presence of the seed.
I think we better to provide the way to set the seed in FixtureMonkeySeedExtension.
For example, with customised test annoatations.
What do you think?
@codesejin Any updates?
@codesejin 최신 소식이 있나요?
I apologize for the delay. I am currently in the process of updating, but I am still working on the logging test..
@seongahjo I’m struggling with testing failure logs using AfterTestExecutionCallback. It’s challenging to determine whether the log is printed after the test finishes, depending on whether the @ShowMeLog annotation is present or not. If you don’t mind, I would greatly appreciate any advice 😅
@codesejin
It’s challenging to determine whether the log is printed after the test finishes, depending on whether the @showmelog annotation is present or not
I think it is better to print the seeds when the test fails without any annotations like @ShowMeLog.
Do you have any reason why the annotation is needed to determine to print seeds?
@seongahjo
As a result, the client is unaware of the presence of the seed. I think we better to provide the way to set the seed in FixtureMonkeySeedExtension. For example, with customised test annoatations.
In previous feedback, I believed it was appropriate for the FixtureMonkeySeedExtension to internally set the seed for tests using annotations, even if the client doesn’t explicitly set the seed themselves. That’s why I thought it was necessary to conditionally print the seed upon test failure based on the presence of the annotation..😅
Thank you for contributing! For the 1.0.24 release, I merge the PR.
Thank you very much for all your support! It has been a truly positive and valuable experience!