This lab contains instructions to enable automated smoke testing in the release.
- Complete lab: Pipeline as code with K8s and Terraform
- Complete lab: UI Testing with Selenium and Azure DevOps
-
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); } } } }
-
Validate if the test passes:
- Run the Web App without debugging
- Right-click the ValidateSiteIsAvailable() test method and select Run Test(s)
-
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
-
Commit your code to trigger the App pipeline.
Upon completion, inspect the release results and verify the Smoke test passed.
- Refactor all the hardcoded timeout values to a variable in the runsettings file. Make them tokenized for replacement during the Release
Return to the Lab index and continue with the next lab