Unit Test

Unit testing is one of the most important levels of test because check the code at the lowest level. This meaning that each line of code should be tested at this level. This level normally is the responsibility of the developer and always when a new code will be added in any project must exist unit tests associated.

Additionally, this level of test helps with the concept called code coverage, this concept is a measure to describe the degree to which the source code has been tested. The coverage could be of different levels for example statement coverage, decision coverage, branch coverage, etc. (See Reference about code coverage).

Related to the standards to follow in WebMap it is possible to mention the next ones:

  • Any project related to unit testing must use Behavior-Driven-Development (BDD) to take advantage of the benefits of this methodology. (See References about BDD).

  • Related to the last point, the tool to use must be the library of the Quality Mate team called Mobilize.QualityMate.BDD.

  • It is important to try to maintain update Mobilize.QualityMate.BDD in the last stable version

  • The level of coverage should accomplish the concept of branch coverage, this must be checked using the build after merging any change.

  • Always is necessarily follow the good practices to write unit testing. (See Good practices to write unit testing).

  • Follow the basic good practices to create any test case. (See Good practices).

  • Document the test case using the basic tags and summaries. (See Test Documentation)

Example following the standards

// <copyright file="UnitTestExample.cs" company="Mobilize.Net">
//        Copyright (C) Mobilize.Net info@mobilize.net - All Rights Reserved
//
//        This file is part of the Mobilize Frameworks, which is
//        proprietary and confidential.
//
//        NOTICE:  All information contained herein is, and remains
//        the property of Mobilize.Net Corporation.
//        The intellectual and technical concepts contained herein are
//        proprietary to Mobilize.Net Corporation and may be covered
//        by U.S. Patents, and are protected by trade secret or copyright law.
//        Dissemination of this information or reproduction of this material
//        is strictly forbidden unless prior written permission is obtained
//        from Mobilize.Net Corporation.
// </copyright>

namespace Mobilize.UnitTest.Example
{
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using Mobilize.QualityMate.BDD;
    using Mobilize.QualityMate.BDD.Annotations;

    [TestClass]
    [Feature("Description of the feature to test")]
    public class UnitTestExample : Feature
    {
        /// <summary>
        /// Document in a better way the scenario to test.
        /// <seealso href="https://theLinkOfTheTestCaseInAzureDevOps"/>
        /// </summary>
        [TestCategory("Unit Testing")]
        [Scenario("Describe an example to follow the standars")]
        public void ADescriptiveNameRelatedWithTheScenarioToTest()
        {
            this.RunScenario(     
                given => this.FirstStep(),
                when => this.SecondStep(),
                then => this.ThirdStep());
        }

        /// <summary>
        /// Document each method if it is necessary
        /// </summary>
        private void FirstStep()
        {
            // Setup or init the aspects or context to use in the test
        }

        private void SecondStep()
        {
            // Some event occurs or something change
        }

        private void ThirdStep()
        {
            // Ensure some outcomes
            Assert.IsTrue(true);
        }
    }
}

Notes

  • It is valid to add any other NuGet or dependency in the project depending on the necessity.

  • Many teams create a base class with the common steps or configurations in order to use in the other classes to the unit tests.

Last updated