How and what to Test

I'm trying to become a more professional developer so I'm adapting to best practices and all that But recently i wanted to get into Unit testing my C# applications but ran into an issue: I have no idea what to even test in the first place, for example what if i develop a desktop applications, a Discord bot, a web API using ASP.NET or even a library, Id love to write Unit tests but i have absolutely 0 clue what to actually test someone send help :SCcrying:
4 Replies
Omnissiah
Omnissiah3d ago
you could have low level single class tests up to high level integration tests, but i mean if you want to learn on the argument if you look maybe not courses but even only introductory videos at least you would have some basic knowledge about it
Becquerel
Becquerel2d ago
what the person above me said is extremely true to add onto it, you generally are writing either unit tests or integration tests those terms are a bit fuzzy but i think the most effective way to think of them is that unit tests are everything which runs deterministically and is isolated while integration tests are everything that do I/O (talk to a database, make http calls, etc) generally, you write unit tests for your 'business logic' - the core parts of your app which are separate from whatever UI framework you're writing it in because those are the parts of your app which typically have complex 'pure' logic integration tests are for broader assertions that your system works, potentially taking into account stuff like the framework you're writing in
Becquerel
Becquerel2d ago
Integration tests in ASP.NET Core
Learn how integration tests ensure that an app's components function correctly at the infrastructure level, including the database, file system, and network.
Becquerel
Becquerel2d ago
for a web api project, i'd write integration tests like this: - can i start the api up, send a request to the /health endpoint, and get the "200 Healthy" response back? - can i send a request to my /foobar endpoint and get an expected status code back? - if i send a request to my /createUser endpoint, and then check the user table in the database, is there a new entry there? etc these tests don't look into the internal logic of your app, but they show you've got everything wired up correctly in asp.net core and in general you should focus on testing the 'public interface' of your app, i.e. the stuff outside consumers get to see. don't test implementation details by themselves unless you have a compelling reason - people not understanding that is why you sometimes see people trying to unit test private methods
Want results from more Discord servers?
Add your server