Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Theory vs Test Nunit

Tags:

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 :(

like image 219
Nathan W Avatar asked Jun 07 '09 12:06

Nathan W


People also ask

What is theory in NUnit?

A Theory is a special type of test, used to verify a general statement about the system under development. Normal tests are example-based.

What is difference between NUnit and MSTest?

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.

Which is better xUnit or NUnit?

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.

What type of testing does NUnit support?

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.


2 Answers

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.

like image 63
Michael Borgwardt Avatar answered Sep 26 '22 01:09

Michael Borgwardt


a theory is an elegant alternative to parameterized test, see my question here at stackoverflow

like image 36
dfa Avatar answered Sep 26 '22 01:09

dfa