We often talk about mocks, even if should use more precise terms like stub, fake and mock. Correct term for these is test double. In this blog post I introduce these different test doubles with code examples.
Anyone who has written unit tests have been fighting with object creations. Some times it is so difficult to create objects used in tests. Test data builders come to rescue! With them I write better tests with less time.
ApprovalTests is one of my favorite NuGet in C#. It helps you to verify is your method's output or object changed. It will automatically visualize the error by opening your diff tool and shows the difference there. I really recommend you to become familiar with this if you are a C# developer.
This is something that has made my integration tests better. You define a test method to run in transaction and rollback at the end of each test. This makes it possible to write integration tests that write to the database. And tests won't leave any "garbage" there because rollback at the end of the test undoes all database updates (and inserts and deletes). If this is possible in your language and testing framework I strongly recommend it. In this blog post I will explain how you can do it with NUnit in C#.
SonarQube has two rules about constant and static readonly:
- Public constant members should not be used and
- Static readonly constants should be const instead.
I wrote this blog post to learn these rules and their difference. Now I know when to use const and when to use static readonly.
I didn't clearly understand what is field and property in C#. So I decided to write this blog post to finally learn what is field and what is property and how I should use them.