Show Menu

MS Test Example

Example Test

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

namespace UnitTests
    //Class Decorator
    public class EmailValidationTests
        private EmailValidationLogic _validationLogic;

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

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

        //This code runs before each test
        public void Setup()
            _validationLogic = new EmailValidationLogic();

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

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

        //This is code runs after each test
        public void TearDown()

        //Example Test Method
        public void EmailShouldNotHaveMoreThanOneAtSymbol()
            bool expected = false;

            bool result = _validationLogic.IsEmailValid("");

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

        //Test Exception Being Thrown
        public void DivideMethodTest()
            int x = 1;
            int y = x/0;


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

          ISTQB Test Automation Engineering Cheat Sheet
          Cypressio Cheat Sheet
          Selenium WebDriver Cheat Sheet Cheat Sheet

          More Cheat Sheets by GregFinzer

          T4 Templates Cheat Sheet
          Crownpeak Models Cheat Sheet