Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
swdev:dotnet:unit_testing_with_nunit [2015/08/07 10:19]
smayr [Usage]
swdev:dotnet:unit_testing_with_nunit [2016/06/30 15:38] (current)
smayr [Pattern AAA]
Line 63: Line 63:
     * Run Test Runner, and create new Test project (File > New Project).     * Run Test Runner, and create new Test project (File > New Project).
     * Select assembly or application containing unit tests (Project > Add Assembly). Note: These assemblies and applications must have a reference to ''NUnit.Framework.dll'' in their individual projects.     * Select assembly or application containing unit tests (Project > Add Assembly). Note: These assemblies and applications must have a reference to ''NUnit.Framework.dll'' in their individual projects.
 +
 +== Pattern AAA ==
 +Modern tests contain three parts:
 +<code csharp>
 +[TestMethod]
 +public void GetCount_ItemCountIsZero_NoNewMessages()
 +{
 +    //Arrange
 +    Mailbox mailbox = new Mailbox();
 +      
 +    //Act
 +    var result = mailbox.GetCount(0);
 +      
 +    //Assert
 +    Assert.AreEqual("No new messages.", result);
 +}
 +</code>
 + 
 +This can be summed up as a pattern:
 +  * Arrange: setup everything needed for the running the tested code. This includes any initialization of dependencies, mocks and data needed for the test to run.
 +  * Act: Invoke the code under test.
 +  * Assert: Specify the pass criteria for the test, which fails it if not met.
 +
 +Source: [[http://www.typemock.com/unit-test-patterns-for-net|Unit Test Patterns for .NET]]