Using Should for unit test assertions
See original GitHub issueI’ve been contributing to this project writing some unit tests and I was wondering if we would be interested in using the Should assertion library.
I love using Should and I find myself missing it greatly when writing tests in the old Assert.Equal(expectation, actual)
way.
The library allows you to use extension methods to make your assertions. The syntax is actual.ShouldEqual(expectation)
. This eliminates the need to remember the order of the arguments in the assertion. It also allows you to use intellisense to find assertions for the type that you are testing easily.
Issue Analytics
- State:
- Created 8 years ago
- Comments:9 (6 by maintainers)
Top Results From Across the Web
How to write better unit test assertions
The first two sections exercise the code on some relevant scenario. The assert section ensures that the code behaves as expected. Assertions ......
Read more >Best Practices for Assertions in Unit Tests
1. The Unit Test Does Not Include an Assertion ... The first, and most egregious, is when we write a unit test without...
Read more >Stop requiring only one assertion per unit test
There's nothing wrong with multiple assertions in a single test. The above example illustrates the benefits. A single test case can have ...
Read more >Are asserts or unit tests more important?
The main differences are that asserts function as sanity checks and see real inputs, whereas unit tests run on specific simulated inputs and...
Read more >Unit Testing Tutorial: 6 Best Practices to Get Up To Speed
It asserts the hypothesis itself. Asserting something represents the essence of testing.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
let’s keep with Shouldly as it is current in our codebase as you said @stevejgordon
@tonysurma We have Shoudly in place already and it’s used it a fair number of tests, therefore I would propose we stick with that so we have a single library in use. I’ve used both and the differences seem to be negligible.
If you’re happy, I would propose we close this?