-
Notifications
You must be signed in to change notification settings - Fork 163
Add custom value formatter support to FsCheck.NUnit #731
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
base: master
Are you sure you want to change the base?
Conversation
Co-authored-by: kurtschelfthout <164917+kurtschelfthout@users.noreply.github.com>
Co-authored-by: kurtschelfthout <164917+kurtschelfthout@users.noreply.github.com>
kurtschelfthout
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't work. When I run the test I still see:
Testing with value: CustomType(29)
Ok, passed 1 test.
i.e. I don't see the CUSTOM message.
Also, your test needs improvement. What you should do instead is something like ResultOutputTests immediately below where you add TestContextFormatterTests: write a test that takes CustomTYpe as argument, which always fails, mark it as Ignore so it doesn't run with the normal test run, and then run it manually and check the output contains CUSTOM. See the test should show full result info on failures in Async/Task-returning test methods for how to do that.
kurtschelfthout
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't work. When I run the test I still see:
Testing with value: CustomType(29)
Ok, passed 1 test.
i.e. I don't see the CUSTOM message.
Also, your test needs improvement. What you should do instead is something like ResultOutputTests immediately below where you add TestContextFormatterTests: write a test that takes CustomTYpe as argument, which always fails, mark it as Ignore so it doesn't run with the normal test run, and then run it manually and check the output contains CUSTOM. See the test should show full result info on failures in Async/Task-returning test methods for how to do that.
…utput - Introduce public ValueFormatter class with AddFormatter method - Format test arguments and shrink values using registered custom formatters - Update test to demonstrate custom formatter usage - Custom formatters work with verbose output during test execution Co-authored-by: kurtschelfthout <164917+kurtschelfthout@users.noreply.github.com>
Fixed in commit a5864df. After investigating, I found that NUnit's I've implemented a Updated the test to use this API and it now passes, correctly showing formatted output during test execution. |
FsCheck.NUnit was using
printfnfor test output, bypassing NUnit's test execution context. This prevented proper output capture by test runners and made it impossible to customize value formatting in test output.Changes
ValueFormatter.AddFormatter<'T>()method for registering custom formattersprintfnwithTestContext.WriteLineand use registered custom formatters for argument and shrink outputTestContext.WriteLinefor test result output when not quietBackground
NUnit's
TestContext.AddFormatterdoes not integrate withTestContext.WriteLine- those formatters are used elsewhere in NUnit's infrastructure. FsCheck.NUnit now provides its own formatter registry that IS used for test output during verbose mode execution.Example Usage
Aligns with FsCheck.Xunit's use of
ITestOutputHelper.WriteLineand provides custom value formatting for test output.Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.