TDD: Testing with Stub Methods

Adding flexibility to return values using Stub methods. Continuing on my “Testing with Dummy objects” article, you might have noticed a limitation with regards to the return value – only one was allowed. In situations where multiple return values are needed, Stub methods provide an alternative. In my previous example, GetSalesOutcome() only provided one return…

TDD: Refactoring with Polymorphism

Using polymorphism to refactor SRP violations. Single Responsibility Principle (SRP) violations are one of the most common issues found in code. Either the class or its behavior is attempting to fulfill more than one primary purpose. In this example, I will illustrate how polymorphism provides a powerful method to refactor violations of SRP. I will…

TDD: Mocking with Dummy Objects

Using custom objects in place of a mocking framework. When it’s desired to avoid the overhead of a mocking framework and its functionality isn’t required, developers may elect to provide their own dummy objects instead. In this article I will illustrate a simple example of writing my own dummy object which are mocks that represent…

TDD: Assets

Leveraging overloaded Assert() methods to enhance test methods. Continuing from my TDD: Mocking with Dummy objects article, I wanted to illustrate some examples of other Assert() methods available for use to enhance testing results. As illustrated in my last example, you may just utilize the traditional Assert.AreEqual() method, passing it the expected and actual results…