Unit testing with MSTest

Structure

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
using Microsoft.VisualStudio.TestTools.UnitTesting;

[TestClass]
public class MyClassTests
{

[TestMethod]
public void UnitOfWork_InitialCondition_ExpectedResult()
{
// Arrange
// Act
// Assert
Assert.AreEqual(expected, actual);
}
}

Other Asserts

1
Assert.IsTrue

ExpectedException

1
2
3
4
[ExpectedException(typeof(MyException))]
[TestMethod]
public void UnitOfWork_InitialCondition_ExpectedResult()
{ ... }

References