What’s next for asa.unittest now that Azure Stream Analytics comes with a unit testing tool.

Last month the ASA team updated azure-streamanalytics-cicd, their companion npm package. It now includes the addtestcase and test commands that add support for query unit testing. These commands are well documented and quite easy to use.

I’ve just released asa.unittest 1.1.0 that now comes with helper tools to migrate tests built for asa.unittest to the new format expected by the CI/CD tool. I document the process below.

Future of asa.unittest (or lack of)

To be honest I’ve not yet decided what to do with asa.unittest now that it’s been made redundant. This module has been both a challenging project and a big accomplishment for me. I’m not sure there’s a point in investing more time now that unit testing is supported by the product directly.

I’m pretty happy that building it provided coverage while the ASA team was working on enabling unit testing themselves. What is awesome is that I was also invited by them to review their design, and was able to contribute to it (to be noted, I’m a Microsoft employee at the time of writing).

Also I learned a ton about PowerShell, and releasing and maintaining an open source tool. That’s been fantastic.

So 5 stars, I would do it again, but let’s move on!

Migrating from asa.unittest to azure-streamanalytics-cicd

It’s actually pretty straightforward to move from one tool to the other. There are just 3 areas that need an intervention.

1 - Output test files

In asa.unittest, the expected output files (*~output~*~*.json) should be formatted as proper arrays of messages ([{...},{...}]).

In azure-streamanalytics-cicd, the test runner instead expects a line separated format ({...}{...}). It’s actually not a bad idea since it’s the format being outputted during local runs. It should make test generation easier.

I’ve added Set-AutNewFormatOutputFiles as a new command to asa.unittest to transform existing files easily. What it does is copy existing output files in an archive folder, and update the format of the files in the existing folder. It’s meant to facilitate the conversion process, since asa.unittest now supports both formats.

To make things clear:

  • Run Set-AutNewFormatOutputFiles to update the output files format in place. It can be run on files in the new format with no impact
  • You can now run both asa.unittest and azure-streamanalytics-cicd on the newly formatted files
  • New tests should be added with the new line separated format

The syntax :


$solutionPath = "C:\users\fleide\Repos\ASATest"
$asaProjectName = "ASA.Application1"
$unittestFolder = "ASA.Application1.Tests"

#if missing, -archivePath will default to ..\1_arrange\archive_<timestamp>

Set-AutNewFormatOutputFiles `
    -solutionPath $solutionPath `
    -asaProjectName $asaProjectName `
    -unittestFolder $unittestFolder

If a file can’t be archived, it won’t be updated. I tested it extensively, but please reach out on GitHub if you encounter any issue.

2 - Test manifest

In asa.unittest, the runner knows what test to run using a naming convention on test files. It was easy for me to implement, but was not the best long term idea (if only for the test files potential duplications).

I was planning to switch to a manifest based test declaration, azure-streamanalytics-cicd does it for me.

For new tests, azure-streamanalytics-cicd now has an addtestcase command.

For existing tests, asa.unittest now comes with New-AutManifestFromFiles. It will read an existing 1_arrange folder and generate a corresponding testConfig.json file with the proper syntax:

{
  "Script": "",
  "TestCases": [
    {
      "Name": "Case 1",
      "Inputs": [
        {
          "InputAlias": [Input alias string],
          "Type": "Data Stream",
          "Format": "JSON",
          "FilePath": [Required],
          "ScriptType": "InputMock"
        }
      ],
      "ExpectedOutputs": [
        {
          "OutputAlias": [Output alias string],
          "FilePath": "Required",
          "Required": true
        }
      ]
    }
  ]
}

The syntax :


$solutionPath = "C:\users\fleide\Repos\ASATest"
$asaProjectName = "ASA.Application1"
$unittestFolder = "ASA.Application1.Tests"

#if missing, -outputFilePath will default to ..\1_arrange\testConfig_<timestamp>.json

New-AutManifestFromFiles `
    -solutionPath $solutionPath `
    -asaProjectName $asaProjectName `
    -unittestFolder $unittestFolder

I also tested this one extensively. Again, please reach out on GitHub if you encounter any issue.

3 - Test calls

Now that output test files are converted to the new format, and we have a manifest, calling azure-streamanalytics-cicd will be easy:


#The new command expects a path to either asaproj.json (VSCode) or <project>.asaproj (Visual Studio) in the projectFullPath

$projectFullPath = "C:\users\fleide\Repos\ASATest\ASATest1\asaproj.json"
$testFullPath = "C:\users\fleide\Repos\ASATest\ASATest1.Tests\testConfig.json"
$outputPath = "C:\users\fleide\Repos\ASATest\ASATest1.Tests\testRuns\" + (Get-Date -Format "yyyyMMddHHmmss")

azure-streamanalytics-cicd test -project $projectFullPath -testConfigPath $testFullPath -outputPath $outputPath

Which previously was equivalent to:

$asaProjectName = "ASA.Application1"
$solutionPath = "C:\users\fleide\Repos\ASATest\"
$unittestFolder = "ASA.Application1.Tests"
$asanugetversion = "3.0.0"
Start-AutRun `
    -asaProjectName $asaProjectName `
    -solutionPath $solutionPath `
    -unittestFolder $unittestFolder `
    -asanugetversion $asanugetversion `
    -verbose

Hope that helps! Any issues: please reach out on GitHub.