✅ Learning testing and test-driven development
Hello guys, I need to learn how to perform testing in C# and I need to learn about the test-driven development. I need to pick up a library to get started but it seems there are so many libraries.
My first question is, why do we have so many libraries for testing? How is each one unique from the other please.
Also, is there any recommended library to use to get started? (Any docs if can be shared also? :c)
35 Replies
There are many testing libraries in C# because different projects have unique needs—some focus on unit testing (MSTest, NUnit, xUnit), while others support BDD (SpecFlow). They vary in syntax, ecosystem integration, and features.
For beginners, xUnit is recommended due to its modern approach, clean syntax, and strong .NET Core support. If you're in an enterprise Microsoft environment, MSTest is a solid choice.
Quick Comparison - MSTest: Best for Microsoft ecosystem, built into Visual Studio. - NUnit: Feature-rich, supports parallel execution. - xUnit: Modern, DI-friendly, good for .NET Core. - SpecFlow: For BDD-style testing with Gherkin. Docs to Get Started - xUnit: xunit.net - NUnit: nunit.org - MSTest: MS Docs - SpecFlow: specflow.org
Quick Comparison - MSTest: Best for Microsoft ecosystem, built into Visual Studio. - NUnit: Feature-rich, supports parallel execution. - xUnit: Modern, DI-friendly, good for .NET Core. - SpecFlow: For BDD-style testing with Gherkin. Docs to Get Started - xUnit: xunit.net - NUnit: nunit.org - MSTest: MS Docs - SpecFlow: specflow.org
Unknown User•2mo ago
Message Not Public
Sign In & Join Server To View
hmm for now, it's just a uni project where I need to test the project I'm building, I can just stick with xUnit?
Unknown User•2mo ago
Message Not Public
Sign In & Join Server To View
oh each has there use-case, basically a developer would need to work with all of these 3 at some point ?
Unknown User•2mo ago
Message Not Public
Sign In & Join Server To View
euhhhhh I don't know exactly what the
async init
stands for right now but I now I would need to use multi-threading in my project, so if I use xUnit it might be an issue? (Since tUnit is recent, it's better to just go with it ?)Unknown User•2mo ago
Message Not Public
Sign In & Join Server To View
oh, we can use different testing libraries/framework at the same time?
Unknown User•2mo ago
Message Not Public
Sign In & Join Server To View
like with the issue of the async thing for xUnit, we can just solve it using tunit ?
Unknown User•2mo ago
Message Not Public
Sign In & Join Server To View
yep I see, thanks ! I have an overview now, just have a look at my lecture slides, they mentioned these 3 libraries, I will just stick with xUnit for now.... one last question, when we speak about testing, we often refer to "stub/fake/mocks" what are these? I read that there are even libraries to "generate" them

Unknown User•2mo ago
Message Not Public
Sign In & Join Server To View
Noted, thanks once more 👍
by the way, out of curiosity, why is it not recommended to use MSTest ?
Unknown User•2mo ago
Message Not Public
Sign In & Join Server To View
yep I see
Unknown User•2mo ago
Message Not Public
Sign In & Join Server To View
ah, like for legacy reasons ?
Unknown User•2mo ago
Message Not Public
Sign In & Join Server To View
yeah I see
Unknown User•2mo ago
Message Not Public
Sign In & Join Server To View
yep
Thanks !
If you want to go deep on testing, read Vladimir Khorikovs book on it
Excellent resource
Unknown User•2mo ago
Message Not Public
Sign In & Join Server To View
this one ?

Yeah
It's amazing
But more of a resource to deepen your knowledge, so it might be overkill if you just want to get a grasp of the topic for uni
yep, I will use it as a reference and go deeper in it if needed, thanks !
One thing I don't understand, we say unit tests are "automated". But the thing is, we write the test cases, no? In what way are they automated and don't run "manually" ? How would it be different if I need to implement everything "manually" rather than "automatically" ?
You have to write them once and you can automatically run them as part of e.g. dotnet test forever
You don't have to sit down yourself
And start all the tests like you would when debugging your app
Oh okay I see now, thanks !
Hello, small question, when we write unit tests, do we actually write test for ALL methods? I read that we only write unit tests for the "critical" part of our application. But basically, all methods aren't critical to an application?
Unknown User•2mo ago
Message Not Public
Sign In & Join Server To View
yeah, then how do choose which methods to write in the unit test? Are there some best practices to follow?
Unknown User•2mo ago
Message Not Public
Sign In & Join Server To View
yep I see, thanks !
Last question :c... I was just reading some docs... there it talks about using unit tests from microsoft-in built framework, this is what I should avoid using, the MSTest built-in framework? It also mentions testing unit test using "test explorer". The test explorer can only be used if I'm using MSTest, else I should use command like
dotnet test
?Unknown User•2mo ago
Message Not Public
Sign In & Join Server To View