What the C# team should do real quick

By on 11/11/2019

Try to imagine a computer system as a living organism. The call stack is the organic part, and events or triggers are part of the nervous system. In any case, the basic structural element is a cell. That can be a class or an object. A cell is a 3 dimensional structure with many essential parts, but not all of them have any external function, like communiting with neighbor cells. The purpose of these elements is to ensure the cell keeps functioning, and the ‘higher’ purposes are fulfilled. To take this just a little further, the code inside a class can be the DNA, the public interfaces the cell wall (membrane), function calls happen when the receptors are being triggered, and liquids and nutritions is just good old fashion data being passed along.

This is not supposed to be a biology class, especially because I wouldn’t have the expertise. But when you read a bit about subcellular components, perhaps you can also see more resemblances to the different components a class exists of.

I believe we have to start considering unit tests as part of the subcellular components. Let me explain. Unit Tests are not important during runtime you may say, but who says the runtime is the whole lifecycle of a class? A class is much more than that. It’s part of the result of a complex thinking process, dividing bigger ideas into pieces, whatever the pattern may be. And all this bigger lifecycle is subject to continuous development, which results in changes. And during this whole process of changing over and over (like mutations and duplications of cells), every function has to keep working. And it is our unit tests that make sure of that! They make sure of the survival of our class, and that it can work as it was supposed to work. When classes evolve, their unit tests must be adapted constantly, and as early as possible.

I’ll come to the point. I have to admit that this partly comes from the principles in Angular components (services, directives…) that I’m working with since quite a while now. And there, the unit tests (Jasmine) always come directly with and next to a component.

I would love to see this same principle in .NET projects. I’m sure that can be solved with tricks and compile conditions, but the solution should come directly from the language. I mean there is no reason to include it into release assemblies, but it would greatly improve the programmers day-to-day business, and help us to always keep the tests up-to-date, the code coverage high, and to even work test driven. The live unit tests are a great feature in VisualStudio, but the unification of classes and their unit tests could be the next evolutionary step that can help us to keep our classes alive and make our systems grow in a healthy way.