Welcome to the Inedo Forums! Check out the Forums Guide for help getting started.

If you are experiencing any issues with the forum software, please visit the Contact Form on our website and let us know!

Unit Tests Results Summary



  • We have an execution plan whose job it is to execute a number of unit tests across a range of test projects.

    On completion of the tests, we're currently posting out a notification which contains a link to the test-results page as follows:

    set $TestResultsUrl = http://ourbuildserver/executions/test-results?executionId=$ExecutionId

    set $testsCompletedNotifcationMessage = $ApplicationName - $ReleaseName finished executing\n<$TestResultsUrl|Results>;

    Is there a system variable or function for getting the actually results summary (as presented on the test-results page) within the execution context so we can include it in the notification message body too?

    Product: BuildMaster
    Version: 5.6.8



  • There is nothing built-in to do this, but you could do this with a custom variable function.



  • Thanks Alex,

    As recommended, I've created a variable function extension for this, which has worked perfectly:

      [ScriptAlias("TestResultsSummary")]
      [Description("Returns a test results summary string for the execution in the current scope.")]
      [Category("Unit Testing")]
      public class TestResultsSummaryVariableFunction : ScalarVariableFunction
      {
        [DisplayName("executionId")]
        [Description("The ID of the execution whose test results summary will be returned. If empty, the execution ID "
               + "in the current context will be used.")]
        [VariableFunctionParameter(0, Optional = true)]
        public int? ExecutionId { get; set; }
    
        protected override object EvaluateScalar(IGenericBuildMasterContext context)
        {
          int? executionId = this.ExecutionId ?? context.ExecutionId;
    
          if (executionId == null || executionId <= 0)
            return "INVALID EXECUTION ID";
    
          var testResults = DB.BuildTestResults_GetTestResults(executionId);
    
          var runCount = testResults.Count;
          var passCount = 0;
          var failCount = 0;
          var inconclusiveCount = 0;
    
          foreach (var result in testResults)
          {
            if (result.TestStatus_Code == Domains.TestStatusCodes.Passed)
              passCount++;
    
            if (result.TestStatus_Code == Domains.TestStatusCodes.Failed)
              failCount++;
    
            if (result.TestStatus_Code == Domains.TestStatusCodes.Inconclusive)
              inconclusiveCount++;
          }
    
          return string.Format("{0} run, {1} passed, {2} failed, {3} inconclusive", runCount, passCount, failCount, inconclusiveCount);
        }
      }




Inedo Website HomeSupport HomeCode of ConductForums GuideDocumentation