Show Menu

MSTest Cheat Sheet by

MS Test Example
test     testing     microsoft     mstest

Example Test

using Microsoft.VisualStudio.TestTools.UnitTesting;
using ValidationLogic;

namespace UnitTests
{
    //Class Decorator
    [TestClass]
    public class EmailValidationTests
    {
        private EmailValidationLogic _validationLogic;

        //Optional, rarely used. Executes before all tests in the assembly are run
        [AssemblyInitialize]
        public static void AssemblyInit(TestContext context)
        {
        }

        //Optional, rarely used. Runs once before all the tests in this class run
        [ClassInitialize]
        public static void TestFixtureSetup(TestContext context)
        {
        }

        //This code runs before each test
        [TestInitialize]
        public void Setup()
        {
            _validationLogic = new EmailValidationLogic();
        }


        //Optional, rarely used. Runs once after all tests in the assembly are run
        [AssemblyCleanup()]
        public static void AssemblyCleanup()
        {
        }

        //Optional, rarely used. This runs once after all the tests in this class are run
        [ClassCleanup]
        public static void TestFixtureTearDown()
        {
        }

        //This is code runs after each test
        [TestCleanup]
        public void TearDown()
        {
        }

        //Example Test Method
        [TestMethod]
        public void EmailShouldNotHaveMoreThanOneAtSymbol()
        {
            //Arrange
            bool expected = false;

            //Act
            bool result = _validationLogic.IsEmailValid("jsmith@@hotmail.com");

            //Assert
            Assert.AreEqual(expected, result, "Email should not have more than one @");
        }

        //Test Exception Being Thrown
        [TestMethod]
        [ExpectedException(typeof(System.DivideByZeroException))]
        public void DivideMethodTest()
        {
            int x = 1;
            int y = x/0;
        }
    }
}

Download the MSTest Cheat Sheet

2 Pages
//media.cheatography.com/storage/thumb/gregfinzer_mstest.750.jpg

PDF (recommended)

Alternative Downloads

Share This Cheat Sheet!

Like this cheat sheet? Check out our sponsors!

Readability-Score.com is a collection of tools to make your writing better. More readabile content means higher conversion rates and better reader engagement. Measure website and document readability, measure keyword density and more!

Click Here To Get Started!

 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          jasmine JS testing Cheat Sheet
          Selenium WebDriver Cheat Sheet Cheat Sheet
          Excel 2013 Keyboard Shortcuts Keyboard Shortcuts

          More Cheat Sheets by GregFinzer