Starters Guide To Unit Testing In C#

Kenji Elzerman
13 min readJul 12, 2023

While coding is fun and all, you need to make sure your code is always working. When something goes wrong customers usually blame the developers, but 7 out of 10 times it’s a wrong input but the customer. 2 out of 10 times it’s a logic problem (“well, didn’t see that one coming”), and 1 out 10 times it's a developers error.

We, developers, cannot think for a customer or all the things a user can do. But we can make sure our code works as it should. Therefore, we should test our code. Not the application, but the logic that makes the application work. This is what we call ‘unit testing’.

Introducing Testing

Testing software is really important for different reasons. You don’t want your users to run into any kind of strange behavior. We test our software to make sure the application(s) work as intended. We also test to filter out the errors and unlogical flows.

There are many ways to test an application. The most known way is to simply start up the application, click around, enter some random data, and hope everything works. This is usually done by dedicated testers; people that had the education to find errors.

But since I am a developer (and chances are you are too) I don’t want to click around and test my application… Although I should. The problem is users don’t…

--

--

Kenji Elzerman

C# developer | Kens Learning Curve | C# teacher for people diagnosed with ADHD and/or autism | world traveler