Search code examples
c#azure-devopsazure-pipelinesnunitrestsharp

How to configure RestSharp test to run on AzureDevOps


Its my first time of implementing a test framework with RestSharp + NUnit. I have not seen any information on Restsharp page stating it support for AzureDevOps.

I just wanted to know anyone had successfuly ran RestSharp test on AzureDevOps?

Thanks.

I am currently doing a POC on RestSharp on my local machine. I would like to be able to run the test on Azure pipeline. I wanted to know if anyone has implemented this successfully. Does RestSharp supports AzureDevOps?


Solution

  • Yes,it's supported to run RestSharp tests with NUnit on Azure DevOps.

    In your azure-pipelines.yml file, you need to specify the steps for restoring NuGet packages, building your solution, and running the tests.

    Here is the yaml sample which based on RestSharp tests with NUnit on github repo:

    trigger: none
    
    pool:
      vmImage: 'windows-latest'
    
    variables:
      buildConfiguration: 'Release'
      solution: '**/*.sln'
    
    steps:
    - task: NuGetToolInstaller@0
    
    - task: NuGetCommand@2
      inputs:
        restoreSolution: '$(solution)'
    
    - task: VSBuild@1
      inputs:
        solution: '$(solution)'
        configuration: '$(buildConfiguration)'
    
    - task: VSTest@2
      inputs:
        testSelector: 'testAssemblies'
        testAssemblyVer2: |
          **\$(BuildConfiguration)\*DataDriven*.dll    # this is the test dll built in above step
          **\$(BuildConfiguration)\*test*.dll
          !**\*TestAdapter.dll
          !**\obj\**
        searchFolder: '$(System.DefaultWorkingDirectory)'
    
    

    The test result passed:

    enter image description here

    Hope it helps!