azureazure-devopsazure-pipelinesvstest

Test project not finding my test dll when running VSTest


I have an azure pipline and part of the yaml file is for the regression tests, so the code below works good but I do not like hard coded paths, as we all know these can change over time.

- task: VSTest@2
  displayName: 'Regression Public'
  inputs:
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'  
    testSelector: testAssemblies
    testAssemblyVer2: |
      C:\KevTestWork\Release\net6.0\KevTestWork.Regression.dll
    testFiltercriteria: 'Priority=1|TestCategory=RegressionPublic'

As I say the above works nice, the tests are found and they run. But what I want to do is use a variable to remove the hard coded element. The code below runs but the tests are not found

- task: VSTest@2
  displayName: 'Regression Public'
  inputs:
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'  
    testSelector: testAssemblies
    testAssemblyVer2: |
        **\*Regression*.dll
        !**\*KevTestWork.Regression.dll
        !**\obj\**
    searchFolder: '$(System.DefaultWorkingDirectory)'  
    testFiltercriteria: 'Priority=1|TestCategory=RegressionPublic'

Now in the build task which runs prior to this test task I see these statements

CopyFilesToOutputDirectory:
Copying file from "D:\a\1\s\KevTestWork.Regression\obj\Release\net6.0\KevTestWork.Regression.dll" to "C:\KevTestWork\Release\net6.0\KevTestWork.Regression.dll".
Copying reference assembly from "obj\Release\net6.0\refint\KevTestWork.Regression.dll" to "D:\a\1\s\KevTestWork.Regression\obj\Release\net6.0\ref\KevTestWork.Regression.dll".
KevTestWork.Regression -> C:\KevTestWork\Release\net6.0\KevTestWork.Regression.dll
Copying file from "D:\a\1\s\KevTestWork.Regression\obj\Release\net6.0\KevTestWork.Regression.pdb" to "C:\KevTestWork\Release\net6.0\KevTestWork.Regression.pdb".

So my question is is there a built-in azure variable I can use instead of my hard-coded line?

Thanks in advance for any answers


Solution

  • is there a built-in azure variable I can use instead of my hard-coded line?

    Yes, you can (and should!) use a predefined variable such as $(System.DefaultWorkingDirectory), which is the default value of searchFolder.

    Instead of:

    - task: VSTest@2
      displayName: 'Regression Public'
      inputs:
        platform: '$(buildPlatform)'
        configuration: '$(buildConfiguration)'  
        testSelector: testAssemblies
        testAssemblyVer2: |
            **\*Regression*.dll
            !**\*KevTestWork.Regression.dll
            !**\obj\**
        searchFolder: '$(System.DefaultWorkingDirectory)'  
        testFiltercriteria: 'Priority=1|TestCategory=RegressionPublic'
    

    Try the following:

    - task: VSTest@2
      displayName: 'Regression Public'
      inputs:
        platform: '$(buildPlatform)'
        configuration: '$(buildConfiguration)'  
        testSelector: testAssemblies
        testAssemblyVer2: |
            **\*Regression*.dll
            !**\obj\**
        searchFolder: '$(System.DefaultWorkingDirectory)'  
        testFiltercriteria: 'Priority=1|TestCategory=RegressionPublic'
    

    Notes: