NUnit example code?
Solution 1
There are many fine examples on NUnit's developer wiki.
Update as the original link is broken:
Basic examples can be found on the NUnit Documentation Page. Check out the Getting Started/QuickStart subsection, and the Assertions/* subsection.
Solution 2
From my own projects (real life, so not just demos where everything will be nice and simple :)
Both are reasonably small, and although MiscUtil is the bigger of the two, it's mostly a collection of very small, individual components.
MoreLINQ is heavily tested; MiscUtil has patchier coverage as I started it before getting into unit testing.
Solution 3
You should find NUnit samples in with the download of NUnit; these are very good examples of how to use NUnit.
Solution 4
I don't think reading unit tests helps as much as seeing someone writing them and explaining why they are doing the way they are. try some screencasts. DimeCast.Net for example....
Solution 5
This should be useful...
using System.Text;
using NUnit.Framework;
namespace Test.SampleTests
{
[TestFixture]
public class CustomerTestClass
{
[TestCase(1, true)] // valid customer
[TestCase(2, true)] // valid customer
[TestCase(1123123123132, false)] // invlaid customer
public void IsValidCustomerTest(int customerId, bool isValid)
{
Assert.AreEqual(_service.ValidateCust(customerId), isValid);
}
}
}
Taken from here - https://coderwall.com/p/vwvura
davidcm
AutoCAD programmer, mostly ObjectARX(C++,C#), some AutoLISP, some VBA. Working for a midsized manufacturer - awesome to work for because everybody here believes in the value created by custom software.
Updated on June 12, 2022Comments
-
davidcm almost 2 years
I would like to learn how to use NUnit. I learn best by reading then playing with real code. Where can I find a small, simple C# project that uses NUnit in an exemplary manner?
-
msp almost 14 yearsDead links make this choice not so helpful.