Skip to content

Latest commit

 

History

History
89 lines (72 loc) · 3.22 KB

File metadata and controls

89 lines (72 loc) · 3.22 KB

Validating the release with automated Smoke Testing

This lab contains instructions to enable automated smoke testing in the release.

Prerequisites

Configure local Smoke Testing

  1. In the FunctionalTests project, add a smoke test to validate if the website is available:

    SmokeTests.cs (expand to view code)
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using System;
    using System.Net;
    using Assert = Microsoft.VisualStudio.TestTools.UnitTesting.Assert;
    
    namespace aspnet_core_dotnet_core.FunctionalTests
    {
        [TestClass]
        public class SmokeTests
        {
            public TestContext TestContext { get; set; }
    
            private string _siteUrl;
    
            [TestInitialize()]
            public void MyTestInitialize()
            {
                if (TestContext.Properties["siteUrl"] != null)
                {
                    _siteUrl = TestContext.Properties["siteUrl"].ToString();
                }
            }
    
            [TestMethod]
            [TestCategory("Smoke")]
            public void ValidateSiteIsAvailable()
            {
                try
                {
                    var request = WebRequest.CreateHttp(_siteUrl);
                    request.Timeout = 60000;
                    request.ReadWriteTimeout = 60000;
                    using (var response = (HttpWebResponse)request.GetResponse())
                    {
                        // Assert
                        Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Exception: {0}", ex.Message);
                    Assert.Fail(ex.Message);
                }
            }
        }
    }
  2. Validate if the test passes:

    • Run the Web App without debugging
    • Right-click the ValidateSiteIsAvailable() test method and select Run Test(s)

Configure automated Smoke Testing in the release pipeline

  1. Include Smoke tests in the app pipeline:

    • Edit the Azure DevOps app pipeline
    • In the stage Release_Test, edit the deployment Run_functional_tests
      • Rename the deployment name to Run_tests
      • Clone the existing VSTest@2 and place it right below the current task
      • Give the first test task the displayname Run Smoke Tests and ensure it has this setting:
        • testFiltercriteria: TestCategory=Smoke
      • Give the second test task the displayname Run UI Tests and ensure it has this setting:
        • testFiltercriteria: TestCategory=UI
  2. Commit your code to trigger the App pipeline.
    Upon completion, inspect the release results and verify the Smoke test passed.

Stretch goals

  1. Refactor all the hardcoded timeout values to a variable in the runsettings file. Make them tokenized for replacement during the Release

Next steps

Return to the Lab index and continue with the next lab