Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure pipeline: do not build again in order to run tests

Tags:

azure-devops

steps:

- task: DotNetCoreCLI@2
  displayName: dotnet build
  inputs:
    command: 'build'
    arguments: '--configuration $(BuildConfiguration)'

- task: DotNetCoreCLI@2
  displayName: dotnet test
  inputs:
    command: test
    projects: 'Playtech.Neon.Privacy.TestPlaytech.Neon.Privacy.Test.csproj'
    arguments: '--configuration $(buildConfiguration)'

I've noticed that the test step builds the solution again, which is stupid because the solution has already been built by the build step so the tests should just use the bin directory that's already been made.

Can it do this? How?

like image 275
Richard Barraclough Avatar asked Oct 22 '25 03:10

Richard Barraclough


1 Answers

Dotnet commands like test or pack build the project by default.

There are 2 solutions to this:

  1. Include the --no-build argument:
-task: DotNetCoreCLI@2
  displayName: dotnet test
  inputs:
    command: test
    projects: 'Playtech.Neon.Privacy.TestPlaytech.Neon.Privacy.Test.csproj'
    arguments: '--no-build --configuration $(buildConfiguration)'
  1. You can execute the tests on the .dll created by the build like so:
- script: dotnet test Playtech.Neon.Privacy.TestPlaytech.Neon.Privacy.Test.dll
  workingDirectory: '<Path_To_The_Build_Directory>'
  displayName: Run Tests

You can probably do the same with the DotNetCoreCLI@2 Task but I did not test that.

But overall reading the documentation is always a good first step ;)

like image 114
Repcak Avatar answered Oct 25 '25 10:10

Repcak



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!