Previously I wrote an article titled The Right Balance Between Different Types Of Test. This article in intended to act as a complementary piece that will help us to make a better choice when it comes to adopting a testing strategy. In this post we’re going to first see what different types of tests are …
Unit Test
The Right Balance Between Different Types Of Test
Testing strategy is one of those topic that can get very tricky to figure out at the start of project. What I mean is every project depending on the type, needs a specific type of test more than others. For example if a project contains a lot of complicated logic and algorithm then unit testing …
Moq: What’s Wrong With Using VerifyAll
There are some features in the isolation framework (Mocking framework) Moq which I see is used blindly. Most of the time it can which reduce test readability and maintainability. One of the worst offender in this regards is VerifyAll. In this post I’m going to elaborate why this method is so pernicious to readability and …
xUnit BeforeAfterTestAttribute: How to Run Code Before And After Test
Sometimes we need to run a piece of custom code before and after a test and set of tests. One example of this might be when we want to change the thread culture. In this case we change it before test start to run and restore it to its original after test is finished. One …
xUnit: Control the Test Execution Order
Sometime in our tests, we need to control the test execution order. This mostly happens in our integration test and not as often as our unit tests. Some people might even argue that controlling the execution order of unit test is bad practice. You can read more about it here. The main reason to not …
xUnit: Share an SUT Instance Between Two Class Using Collection
In my previous post I talked about how we can Share Expensive Object Between Tests By Using IClassFixture. My previous post is about situations when we want to share a class instance between all test methods. Because a test class is created once per test method so its constructor is executed per test methods. But …
Share Expensive Object Between Tests By IClassFixture
When XUnit run a test method, it’s going to create a new object of our test class for each and everyone of our test method. This can create a problem when the creation of the object is expensive and slow our tests down. But there’s a solution to it, we can use IClassFixture to share …
Interaction Testing With Mocks Leads To A Less Maintainable Unit Test
One of the hallmark of a good unit test is its maintainability. The test that is not maintainable is a pain and there is a higher tendency for it to be ignored. One of the mistakes in software testing is Over-specification of tests. This problem often comes with testing object interaction with a mock object when …
Isolation Frameworks: Why FakeItEasy and NSubstitude Are Better Than Moq
I’ve been trying out different isolation frameworks lately and reading about their features and differences. In terms of feature, most constrained isolation frameworks are almost the same. But there are couple of important points about naming and readability that I think worth paying attention to. I’ve used Moq in my previous projects, but recently, I’ve …
Moq: Working With SetupGet, VerifyGet, SetupSet, VerifySet, SetupProperty
Moq has a set of methods specific to stubbing and verification of properties. In this post I’m going to go over each one of them, and explain when and why to use them. I also discuss their differences and in what situation we might want to use them. Let’s assume we have an interface with …