fixture-monkey icon indicating copy to clipboard operation
fixture-monkey copied to clipboard

feat: log Fixture Monkey seed on test failure

Open codesejin opened this issue 1 year ago • 7 comments

Summary

#990

(Optional): Description

  1. New FixtureMonkeySeedExtension Class
  • 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
  1. afterTestExecution Method
  • 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?

image

Is the Document updated?

codesejin avatar Jul 22 '24 18:07 codesejin

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Jul 22 '24 18:07 CLAassistant

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?

seongahjo avatar Jul 25 '24 05:07 seongahjo

@codesejin Any updates?

seongahjo avatar Aug 08 '24 04:08 seongahjo

@codesejin 최신 소식이 있나요?

I apologize for the delay. I am currently in the process of updating, but I am still working on the logging test..

codesejin avatar Aug 08 '24 10:08 codesejin

@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 avatar Aug 14 '24 05:08 codesejin

@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 avatar Aug 16 '24 08:08 seongahjo

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

codesejin avatar Aug 18 '24 08:08 codesejin

Thank you for contributing! For the 1.0.24 release, I merge the PR.

seongahjo avatar Aug 31 '24 05:08 seongahjo

Thank you very much for all your support! It has been a truly positive and valuable experience!

codesejin avatar Sep 04 '24 11:09 codesejin