C# 9 Record Type simplifies unit tests
C# 9 Record Type simplifies unit tests

Introduction:

Microsoft has released C# 9 with .NET 5.0. It has lots of new features. One feature I am particularly excited about is new Record Type in C# 9. We can now define our data classes with less code, and it looks clean.

It also provides synthesized methods to provide value semantics for equality. Which makes unit test verification lot easier. Without the Record Type, if we use Class to define entity and when a new instance is created in a service under test to pass it to another class’s method, then we need to use It.Is<T>(...)

Aziz Kapadia

Developer, Blogger, Mathematician having 15+ years of experience in Software development and delivery using C#, ASP.NET, WebAPI, Angular etc.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store