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

NUnit Test Tools #433

Merged

Conversation

andreniggemann
Copy link
Contributor

General idea

Given that test are often run in CICD Pipelines it is important to be able to interpret the test failures given the test reports.
To test complex behaviors properly we often have multiple assertions in a single test.

Unless a message is manually specified on an assert, the test report the report will have no meaningful details about the condition that failed and it's possible you have to rely on the line number to find the failed assertion.
Manual messages have further drawbacks like copy paste mistakes or not being maintained once the condition is changed.

The idea to solve this is to create a drop in replacement for NUnit Assert.That that gives more detailed test results.
It relies on the CallerArgumentExpression Attribute to get include the expression being tested in the test report.

The only scenario I know off where this is not a drop in replacement, is when the Assert has a message and format parameters.

Changed behavior for functions/delegates

One maybe controversial, but in my eyes very helpful, aspect, is the handling of functions being passed into the test expression.
The test will implicitly Assert that the function does not throw and then check the return value with the given constraints.
This is helpful in Assert.Multiple blocks because later assertions can still be evaluated.

I think @seveneleven had a good analogy for this:
Given a text input field with validation logic it is very annoying if only the first broken rule is shown.
We have to fix one rule at a time, only to discover the next broken rule.

Given this functionality we only need to wrap expressions that can fail into a lambda and still check all the rules at the same time.

@seveneleven seveneleven self-requested a review July 29, 2024 11:30
seveneleven
seveneleven previously approved these changes Jul 29, 2024
Copy link
Contributor

@seveneleven seveneleven left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this feature a lot!

…for the usage.

Feel free to break the tests and switch between Assert.That and MAssert.That to see the effects.
@1nf0rmagician 1nf0rmagician merged commit dc8680d into PHOENIXCONTACT:release/6 Sep 4, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants