Skip to content

Automated Testing using a DevOps Pipeline

MarkAbrams edited this page Dec 11, 2023 · 7 revisions

Unit tests written using LogicAppUnit can be run as part of a DevOps pipeline, just like any other tests that you might write for C# or other languages. The easiest way to run tests is to use the dotnet test command.

The following sections show example pipeline definitions for GitHub Actions and Azure DevOps pipelines.

GitHub Actions

The key parts of the DevOps pipeline YAML file are shown below. This YAML file targets Windows, Linux (Ubuntu) and macOS platforms.

  • Install the .NET 6.0 SDK:
- name: Setup .NET
  uses: actions/setup-dotnet@v3
  with:
    dotnet-version: 6.0.x
  • Restore NuGet dependencies and build the solution:
- name: Restore dependencies
  run: dotnet restore

- name: Build
  run: dotnet build --no-restore
  • Install and configure the Logic Apps runtime environment, this includes the Azure Functions Core tools, node and Azurite:
- name: Setup node
  uses: actions/setup-node@v3
  with:
    node-version: 18

- name: Install Functions Core tools
  run: 'npm install -g azure-functions-core-tools@4 --unsafe-perm true'

- name: Set Functions Core tools path (Windows only)
  if: matrix.os == 'windows-latest'
  run: 'setx /m Path "C:\npm\prefix\node_modules\azure-functions-core-tools\bin;%Path%"'
  shell: cmd

- name: Install Azurite
  run: 'npm install -g azurite@3.28.0'

- name: Start Azurite services in the background
  run: 'azurite &'
  shell: bash
  • And finally, run the tests:
- name: Run tests
  run: dotnet test --no-restore --verbosity normal --logger "trx"

Azure DevOps pipelines

The key parts of the DevOps pipeline YAML file are shown below. This YAML file targets Windows, Linux (Ubuntu) and macOS platforms.

  • Install the .NET 6.0 SDK:
- task: UseDotNet@2
  displayName: 'Setup .Net'
  inputs:
    packageType: sdk
    version: '6.x'
    installationPath: $(Agent.ToolsDirectory)/dotnet
  • Restore NuGet dependencies and build the solution:
- task: DotNetCoreCLI@2
  displayName: 'Restore dependencies'
  inputs:
    command: restore
    verbosityRestore: Normal
    projects: '$(System.DefaultWorkingDirectory)/**/*.Tests.csproj'

- task: DotNetCoreCLI@2
  displayName: 'Build'
  inputs:
    command: build
    arguments: '--no-restore'
    projects: '$(System.DefaultWorkingDirectory)/**/*.Tests.csproj'
  • Install and configure the Logic Apps runtime environment, this includes the Azure Functions Core tools, node and Azurite:
- task: NodeTool@0
  displayName: 'Install node'
  inputs:
    versionSpec: '18.x'

- task: FuncToolsInstaller@0
  displayName: 'Install Functions core tools'
  inputs:
    version: 'latest'

- task: Npm@1
  displayName: 'Install Azurite'
  inputs:
    command: 'custom'
    customCommand: 'install -g azurite@3.28.0'

- task: CmdLine@2
  displayName: 'Start Azurite services (not Windows)'
  condition: and(succeeded(), ne(variables.matrixName, 'Windows'))
  inputs:
    script: 'azurite &'

- task: CmdLine@2
  displayName: 'Start Azurite services (Windows)'
  condition: and(succeeded(), eq(variables.matrixName, 'Windows'))
  inputs:
    script: 'start /b azurite'
  • And finally, run the tests:
- task: DotNetCoreCLI@2
  displayName: 'Run tests'
  inputs:
    command: test
    arguments: '--no-restore'
    projects: '$(System.DefaultWorkingDirectory)/**/*.Tests.csproj'
    publishTestResults: true
Clone this wiki locally