How to run test with CMD in Azure Devops?



    1. I need to run tests in parallel in Azure DevOps. I have no success with using of runInParallel attribute in the task: VSTest@2. Tests execution time In Azure DevOps is much longer than execution on my machine locally.

    2. I have tried task: CmdLine@2 to launch my test, they run in parallel, and I have the same time execution like on my machine locally. Here, I'm having issues with publishing test results. If there is any fail test - test publishing is not success, If all tests are success - test publishing is success. I want to publish test results in any scenrious. What am I missing?

    My yaml:

    trigger:
     branches:
       exclude:
         - main
         - tests-stress
         - tests-regression
    
    schedules:
      - cron: "00 04 * * *"
        displayName: Daily Automatic Test Run
        branches:
          include:
            - main
      
    pool:
      vmImage: 'windows-latest'
    
    variables:
      solution: '**/*.sln'
      buildPlatform: 'Any CPU'
      buildConfiguration: 'Release'
    
    steps:
    - task: NuGetToolInstaller@1
      displayName: 'Use NuGet 5.8.0'
      inputs:
        versionSpec: 5.8.0
    
    - task: NuGetCommand@2
      inputs:
        restoreSolution: '$(solution)'
    
    - task: VSBuild@1
      inputs:
        solution: '$(solution)'
        msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:DesktopBuildPackageLocation="$(build.artifactStagingDirectory)\WebApp.zip" /p:DeployIisAppPath="Default Web Site"'
        platform: '$(buildPlatform)'
        configuration: '$(buildConfiguration)'
        
    - task: CmdLine@2
      inputs:
          script: 'dotnet test $(Build.Repository.LocalPath)/StressTests/bin/Release/netcoreapp3.1/StressTests.dll --configuration Release --no-build -s $(Build.Repository.LocalPath)/SettingsModelsWorkflows/AllRunSettings/Regression.runsettings --logger trx'
          failOnStderr: false
    
    - task: PublishTestResults@2
      inputs:
        failTaskOnFailedTests: false
        testRunner: VSTest
        testResultsFiles: '**/*.trx'
        searchFolder: '$(Build.Repository.LocalPath)'
    


  • I think the condition attribute is missing:

    - task: PublishTestResults@2
      inputs:
        failTaskOnFailedTests: false
        testRunner: VSTest
        testResultsFiles: '**/*.trx'
        searchFolder: '$(Build.Repository.LocalPath)'
        condition: succeededOrFailed()
    

    From the documentation: In this YAML, PublishTestResults@2 will run even if the previous step fails because of the succeededOrFailed()



Suggested Topics