We have been using Specflow for ages for BDD testing of interfaces. I have also used Living Document to share documentation from our tests for Logic Apps so that the rest of the team and stakeholders can see how things work.

You can use Specflow’s Azure DevOps extension to publish your living document to Azure DevOps in a pipeline.

There are a couple of constraints however:

  • Living Document doesnt work well if you use mono-repo pattern. At present the devops extension which lets you view the documentation assumes there is one document per repo which causes us a problem as each solution within the repo produces its own testable documentation and it will overwrite each time from the perspective of viewing the documentation in Azure DevOps
  • We have a few repos for other solutions and in the extension where you view the documentation you have to flip between them so its a bit of a pain.

What I decided to do instead was to share out living documentation to a sharepoint document library so we have the specflow tested documentation all in one place for all solutions.

Note there is a constraint that you have to download the file to view it as sharepoint limits the running of some of the javascript generated in the html file.

In a previous article I talked about how we can use a Logic App to upload documents to SharePoint from a DevOps pipeline. We would reuse that approach here to solve

Previous Article = Click Here

What we did was put a task group in Azure DevOps which we can add to a pipeline after the tests have completed and it will run any stuff related to Living Document. We left in the original specflow task so if they add support for mono repo but we also chose to generate our own custom document too which you can do via the command line tool as shown in the pipeline below. The steps are:

  • Install .net core sdk
  • Use dotnet to install the specflow cli tool
  • Run the living document command
  • Copy the file to the staging directory
  • Publish it to the build as an artifact
  • Call the logic app which we talked about in the previous article to upload the document to sharepoint

The pipeline looks like the below

This means we now get html files in sharepoint each time a build runs which contains tested documentation explaining how our Logic Apps work and also adding sample messages from our tests.

Ill be talking about this approach more at the Integrate 2022 summit in a few weeks https://www.kovai.co/integrate-2022/?utm_source=biztalk360&utm_medium=blog

The yaml for the pipeline is below


steps:
- task: techtalk.techtalk-specflow-plus.specflow-plus.SpecFlowPlus@0
  displayName: 'SpecFlow+ build step.'
  inputs:
    projectFilePath: '$(AcceptanceTestsFolder)'
    projectName: '$(BUILD.DEFINITIONNAME)'
    testExecutionJson: '**\TestExecution.json'
    workItemPrefix: 'DEVOPS_WI:'
    workItemUrlTemplate: 'https://dev.azure.com/acme/acme-Integration/_queries/edit/{id}'
  condition: succeededOrFailed()

- task: UseDotNet@2
  displayName: 'Use .NET Core sdk '

- script: 'dotnet tool install --global SpecFlow.Plus.LivingDoc.CLI'
  workingDirectory: '$(AcceptanceTestsFolder)'
  displayName: 'Install Specflow CLI'

- script: 'livingdoc feature-folder . --test-execution-json **\TestExecution.json --work-item-prefix DEVOPS_WI: --work-item-url-template https://dev.azure.com/acme/acme-Integration/_queries/edit/{id}  --project-name $(SpecFlowProjectName)  --title $(SpecflowDocumentTitle)'
  workingDirectory: '$(AcceptanceTestsFolder)'
  displayName: 'Run Living Document Generation'

- task: CopyFiles@2
  displayName: 'Copy Files to: $(Build.ArtifactStagingDirectory)'
  inputs:
    SourceFolder: '$(AcceptanceTestsFolder)'
    Contents: LivingDoc.html
    TargetFolder: '$(Build.ArtifactStagingDirectory)'

- task: PublishBuildArtifacts@1
  displayName: 'Publish Artifact: $(BUILD.DEFINITIONNAME)-LivingDocument'
  inputs:
    PathtoPublish: '$(Build.ArtifactStagingDirectory)\LivingDoc.html'
    ArtifactName: '$(BUILD.DEFINITIONNAME)-LivingDocument'

- task: AzurePowerShell@5
  displayName: 'Upload Documentation to SharePoint via Logic App'
  inputs:
    azureSubscription: 'ARM-IT-EAI-DevOpsService-DEV'
    ScriptType: InlineScript
    Inline: |
     Write-Host 'Starting upload to SharePoint via Logic App'
     
     
     Write-Host 'Retrieving Logic App Url'
     $resourceGroup = '[My_RG]'
     $logicAppName = '[My_LA]'
     $triggerName = 'manual'
     $logicAppCallbackUrl = Get-AzLogicAppTriggerCallbackUrl -ResourceGroupName $resourceGroup -Name $logicAppName -TriggerName $triggerName
     $logicAppUrl = $logicAppCallbackUrl.Value
     
     $headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
     $headers.Add("Document-Path", "/Shared Documents/General/Generated Documentation/Living Document Test Specifications")
     $headers.Add("Document-Name", "$(BUILD.DEFINITIONNAME)-LivingDocument.html")
     $headers.Add("Document-SharePoint-Site", "https://acme.sharepoint.com/sites/EAI")
     
     $body = Get-Content -Path $(Build.ArtifactStagingDirectory)\LivingDoc.html  -Raw -Encoding UTF8
     
     $response = Invoke-RestMethod $logicAppUrl -Method 'POST' -Headers $headers -Body $body -ContentType 'text/plain; charset=utf-8'
     
     Write-Host 'Upload to SharePoint via Logic App complete'
     Write-Host $response 
    azurePowerShellVersion: LatestVersion
  enabled: false


 

Buy Me A Coffee