Bonus unit testing part 8: Testing async code

This series of posts accompanies a talk I give about unit testing with the xUnit test framework. Any reader who saw my talk can use this as a reference, others can use this as a starting point to write even better maintainable and reliable code. In my talk, I highlight patterns that work well with easily testable code and combine it all into a working application. All code from these articles can be found in a repository on my GitHub account.

After all the synchronous code I wrote, I wondered how xUnit handles asynchronous code. It is (unsurprisingly) very easy.

Continue reading “Bonus unit testing part 8: Testing async code”

Advertisements

Unit testing part 7: Wiring it all up

This series of posts accompanies a talk I give about unit testing with the xUnit test framework. Any reader who saw my talk can use this as a reference, others can use this as a starting point to write even better maintainable and reliable code. In my talk, I highlight patterns that work well with easily testable code and combine it all into a working application. All code from these articles can be found in a repository on my GitHub account.

I now have some very beautiful code. Well written, fully tested, every part does what it’s supposed to do. Now what?

Continue reading “Unit testing part 7: Wiring it all up”

Unit testing part 6: The horrors of older code

This series of posts accompanies a talk I give about unit testing with the xUnit test framework. Any reader who saw my talk can use this as a reference, others can use this as a starting point to write even better maintainable and reliable code. In my talk, I highlight patterns that work well with easily testable code and combine it all into a working application. All code from these articles can be found in a repository on my GitHub account.

Every line of code I write from now on will have a dozen tests checking every possible behaviour. The problem is my legacy work project, it’s not written with tests in mind. Such a project is not easy to test. Great! Nothing is as fun as a challenge (even if I procrastinate a bit before tackling it).

Continue reading “Unit testing part 6: The horrors of older code”

Unit testing part 5: Even less code with initialization and cleanup

This series of posts accompanies a talk I give about unit testing with the xUnit test framework. Any reader who saw my talk can use this as a reference, others can use this as a starting point to write even better maintainable and reliable code. In my talk, I highlight patterns that work well with easily testable code and combine it all into a working application. All code from these articles can be found in a repository on my GitHub account.

After optimizing tests with data, it’s time to streamline unit tests with initialization and cleanup. xUnit can even reuse code across tests. This can be convenient, but is very dangerous.

Continue reading “Unit testing part 5: Even less code with initialization and cleanup”

Unit testing part 4: Expanding to data driven tests and grouping tests

This series of posts accompanies a talk I give about unit testing with the xUnit test framework. Any reader who saw my talk can use this as a reference, others can use this as a starting point to write even better maintainable and reliable code. In my talk, I highlight patterns that work well with easily testable code and combine it all into a working application. All code from these articles can be found in a repository on my GitHub account.

After the first green test, I want to expand to data driven tests. These tests promote reusability by combining multiple scenarios into one generic test. To end, I’ll categorize tests with metadata.

Continue reading “Unit testing part 4: Expanding to data driven tests and grouping tests”

Unit testing part 3: Running the tests and calculating code coverage

This series of posts accompanies a talk I give about unit testing with the xUnit test framework. Any reader who saw my talk can use this as a reference, others can use this as a starting point to write even better maintainable and reliable code. In my talk, I highlight patterns that work well with easily testable code and combine it all into a working application. All code from these articles can be found in a repository on my GitHub account.

Now that the first unit test is written, I want to execute it to see wether it succeeds or fails. This is facilitated by test runners. I will be covering three: the Visual Studio test runner, the console test runner and the ReSharper test runner.

Continue reading “Unit testing part 3: Running the tests and calculating code coverage”

Unit testing part 2: Getting started with TDD

This series of posts accompanies a talk I give about unit testing with the xUnit test framework. Any reader who saw my talk can use this as a reference, others can use this as a starting point to write even better maintainable and reliable code. In my talk, I highlight patterns that work well with easily testable code and combine it all into a working application. All code from these articles can be found in a repository on my GitHub account.

Now that I’ve explained why I write tests and prefer the xUnit framework, lets write some actual tests. The application I’ll write will run in the Iron Man suit. Unfortunately building such software without errors is reserved for geniuses such as Tony Stark. Believe me, I tried. So I will just build a simple (and very fake) weapons module as backdrop for displaying unit test functionality. The basics of Test Driven Design (TDD) will be explained along the way.

Continue reading “Unit testing part 2: Getting started with TDD”

Unit testing part 1: What and why, different types and frameworks

This series of posts accompanies a talk I give about unit testing with the xUnit test framework. Any reader who saw my talk can use this as a reference, others can use this as a starting point to write even better maintainable and reliable code. In my talk, I highlight patterns that work well with easily testable code and combine it all into a working application. All code from these articles can be found in a repository on my GitHub account.

In this first post I talk about what tests are, why I write them, what the most common types of tests are. I finish with a comparison between the most common frameworks that are used in the .net framework.

Continue reading “Unit testing part 1: What and why, different types and frameworks”