Run Quality tests in your build pipeline by using Azure Pipelines

  1. First step I took I this lab was to run my tests locally using the following commands in visual studio code:

Dotnet build –configuration Release

2. Next I ran the dotnet test command to run the unit tests

Dotnet test –configuration Release –no build

3. This time, I ran the test again but with the –logger option so I could write the results to a log file

4. The output created a TRX file in the TestResults directory

5. In this next step I used WinSCP to log into my remote lab to edit the file azure-pipelines.yml

trigger:

- ‘*’

pool:

vmImage: ‘ubuntu-18.04’

demands:

- npm

variables:

buildConfiguration: ‘Release’

wwwrootDir: ‘Tailspin.SpaceGame.Web/wwwroot’

dotnetSdkVersion: ‘3.1.300’

steps:

- task: UseDotNet@2

displayName: ‘Use .NET Core SDK $(dotnetSdkVersion)’

inputs:

version: ‘$(dotnetSdkVersion)’

- task: Npm@1

displayName: ‘Run npm install’

inputs:

verbose: false

- script: ‘./node_modules/.bin/node-sass $(wwwrootDir) — output $(wwwrootDir)’

displayName: ‘Compile Sass assets’

- task: gulp@1

displayName: ‘Run gulp tasks’

- script: ‘echo “$(Build.DefinitionName), $(Build.BuildId), $(Build.BuildNumber)” > buildinfo.txt’

displayName: ‘Write build info’

workingDirectory: $(wwwrootDir)

- task: DotNetCoreCLI@2

displayName: ‘Restore project dependencies’

inputs:

command: ‘restore’

projects: ‘**/*.csproj’

- task: DotNetCoreCLI@2

displayName: ‘Build the project — $(buildConfiguration)’

inputs:

command: ‘build’

arguments: ‘ — no-restore — configuration $(buildConfiguration)’

projects: ‘**/*.csproj’

- task: DotNetCoreCLI@2 displayName: ‘Run unit tests — $(buildConfiguration)’ inputs: command: ‘test’ arguments: ‘ — no-build — configuration $(buildConfiguration)’ publishTestResults: true projects: ‘**/*.Tests.csproj’

- task: DotNetCoreCLI@2

displayName: ‘Publish the project — $(buildConfiguration)’

inputs:

command: ‘publish’

projects: ‘**/*.csproj’

publishWebProjects: false

arguments: ‘ — no-build — configuration $(buildConfiguration) — output $(Build.ArtifactStagingDirectory)/$(buildConfiguration)’

zipAfterPublish: true

- task: PublishBuildArtifacts@1

displayName: ‘Publish Artifact: drop’

condition: succeeded()

6. Next run commands

git add azure-pipelines.yml

git commit -m “Run and publish unit tests”

git push origin unit-tests

7. Go back to Azure pipelines and run your test.

Perform code coverage testing

  1. The first thing I had to do is run the dotnet new command to create a local tool manifest file

2.Next I ran the dotnet tool install

Dotnet tool install dotnet-reportgenerator-globaltool

3. Next run the dotnet add package command to add the coverlet.msbuild package to the Tailspin.SpaceGame.Web.Tests project

4. Next run the dotnet test to run unit tests and collect code coverage

  1. Last I ran the dotnet tool run to use the report generator

Systems/Network Administrator | DevOps Enthusiast