I was just reading through the Nunit 2.5 docs and came across the Theory attribute, and I'm having a little bit trouble understanding how this is different to a normal unit test and how it could be used.
What makes it different from a normal test?
What situations would you use this kind of test?
I just can't seem to get my head around it :(
A Theory is a special type of test, used to verify a general statement about the system under development. Normal tests are example-based.
MsTest is a native unit testing library that comes with Visual Studio from Microsoft. NUnit is an extra Nuget package that needs to be installed on top and interact with the APIs of Visual Studio. Nunit likely doesn't have direct integration into the native APIs like MsTest does.
As far as NUnit vs. XUnit vs. MSTest is concerned, the biggest difference between xUnit and the other two test frameworks (NUnit and MSTest) is that xUnit is much more extensible when compared to NUnit and MSTest. The [Fact] attribute is used instead of the [Test] attribute.
NUnit is an open-source unit testing framework for the . NET Framework and Mono. It serves the same purpose as JUnit does in the Java world, and is one of many programs in the xUnit family.
A Theory is similar to a parameterized test, with the additional ability to define assumptions under which it must pass, which are checked before actually performing the test and its assertions.
Basically, it could be used if you have a lot of data points and want to check a certain behaviour that should be guaranteed - but not always, only under certain preconditions.
a theory is an elegant alternative to parameterized test, see my question here at stackoverflow
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With