Show Menu

Code example of defining tests in MS Test


Example Test

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace MSTestPoc
    public class MSTestPocTests
        // Code run once before all tests
        public static void ClassInit(TestContext context)

        // Code that is run once after all tests
        public static void ClassCleanup()

        // Code that is run once before each test
        public void Initialize()

        // Code that is run once after each test
        public void Cleanup()

        //Example Test
        public void ExampleTest()
            int expected = 1;

            int? actual = MethodToTest();

            Assert.IsTrue(expected == actual, "expected == actual");

            //Other example assets
            Assert.AreEqual(expected, actual);
            //Assert.Fail("Explicitly Fail");

        public void ParameterizedTest(int value)
            //Do some testing here

        private int MethodToTest()
            return 1;

        private void NotImplementedMethod()
            throw new NotImplementedException();


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

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

          More Cheat Sheets by GregFinzer

          Salesforce CLI Cheat Sheet
          Angular CLI Cheat Sheet
          Elasticsearch Example Queries Cheat Sheet