Code Quality and Automated Code Testing
I’ve heard it said that the top three techniques for improving code quality are:
- Unit testing
- Unit testing
- Unit testing
There is no better defense for the quality of your code than a set of automated code tests.
Automated code testing involves exercising code and testing its behavior by writing more code. So you have a set of code that tests your original code.
The goal of unit testing is to isolate each unit of code in an application and verify that the unit of code behaves as expected in both valid and invalid conditions.
To achieve this goal, we can:
- Refactor our code where necessary into individual units (methods) that can be tested.
- Create a set of tests for each method.
- Tests with valid inputs.
- Tests with invalid inputs.
- Tests that could produce exceptions.
- Execute those tests using a testing framework, such as MSTest or NUnit, both of which are executable from with Visual Studio (ALL editions, including the free Express edition!)
Don’t have time to test? See this post!
For a gentle introduction to automated code testing, see my Pluralsight course: “Defensive Coding in C#”.
This is what one reviewer said about the “Automated Code Testing” module of this course:
This module is an excellent introduction to unit testing with C#!
In fact it should be recommended to C# subscribers as the first place to go to learn about unit testing, before they take any of the .NET unit testing courses in the library. For many this is all they will need,
It takes a viewer on a clear path from zero-knowledge about unit testing to being able to doing useful, real development, unit testing in 45 minutes.
It does a very good job of covering both the mechanics and how to make practical use unit testing.
Enjoy!
Check out my Pluralsight courses!
Ali Bayat — April 1, 2016 @ 6:32 pm
It was great, thank you.
lgbk — May 10, 2016 @ 4:49 am
You are a great trainer, thank you for your work and explain the material very accessible to people who are non-native English spoken