Previous

What is Unit Testing ?

This is the exercide of using other source code to directly call the methods of a class by passing appropriate parameters and then comparing the values with those that are expected.



Unit tests can verify behaviour by using various kinds of :
1) Asset statements (Assert, CollectionAssert, StringAssert)
2) Exceptions (AssertFailedException, AssertInconclusiveException, UnitTestAssertException)
3) Attributes (ExpectedExceptionAttribute)


Microsoft.VisualStudio.TestTools.UnitTesting



Attribute Elements

[ TestClass ] - each test class is marked with this attribute
[ TestClass Attribute ] -
[ TestInitialize ] -
[ TestMethod ] -
[ TestCleanup ] -


[TestClass 
public class UnitTest1
{
   [TestMethod]
   public void TestMethod1()
   {
      Assert.AreEqual(true, true);
   }
}



Assert Class

Members
AreEqual
AreNotEqual
IsTrue
IsFalse




Arrange Act Assert

This type of implementation is a common way of writing unit tests for a method under test
Arrange - this section initializes objects and sets the value of the data that is passed to the method under test
Act - this section involves the method being tested within the necessary parameters
Assert - this verifies that the action has behaved as expected




Options, Environment, Keyboard
EditorContextMenus.CodeWindow.CreateUnitTests
Visual Studio 2010 - right click, context menu "Create Unit Tests"
Removed in Visual Studio 2012





Previous

© 2017 Better Solutions Limited. All Rights Reserved. © 2017 Better Solutions Limited