Jenkins integration for dotnet test

后端 未结 3 1638
南笙
南笙 2020-12-31 11:32

I\'m running a unit test of a dotnet core library using dotnet test. I run the test on my Jenkins slave like this.

dotnet test test/Turbine.Domain.UnitTest -         


        
3条回答
  •  死守一世寂寞
    2020-12-31 12:00

    Thanks Matt and kiml42!

    I'm using dotnet core 2.2 with MSpec as my test framework, and don't need the hacky copying, and can use the trx format (https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-test?tabs=netcore21#examples).

    The test command I use is: dotnet test --logger "trx;LogFileName=UnitTests.trx", which runs tests in each of the test projects, and writes the results to {ProjectFolder}/TestResults/UnitTests.trx

    I do have the MSTest plugin installed, which converts from trx to junit format (https://wiki.jenkins.io/display/JENKINS/MSTest+Plugin).

    I also link to the test results using a post/always/step block as follows:

      post {
        always {
          step ([$class: 'MSTestPublisher', testResultsFile:"**/TestResults/UnitTests.trx", failOnError: true, keepLongStdio: true])
        }
      }
    

    I have the following declarative Jenkinsfile pipeline:

    pipeline {
      agent any
      stages {
        stage('Restore') {
          steps {
            sh 'dotnet restore'
          }
        }
        stage('Test') {
          steps {
            sh 'dotnet test --logger "trx;LogFileName=UnitTests.trx"'
          }
        }
        stage('Build') {
          steps {
            sh 'dotnet build'
          }
        }
        stage('Stop') {
          steps {
            sh 'sudo systemctl stop core-app.service'
          }
        }
        stage('Deploy') {
          steps {
            sh 'rm -rf /var/www/core-app'
            sh 'cp -R . /var/www/core-app'
          }
        }
        stage('Start') {
          steps {
            sh 'sudo systemctl start core-app.service'
          }
        }
      }
      post {
        always {
          step ([$class: 'MSTestPublisher', testResultsFile:"**/TestResults/UnitTests.trx", failOnError: true, keepLongStdio: true])
        }
      }
      tools {
        msbuild '.NET Core 2.2.103'
      }
      environment {
        ASPNETCORE_ENVIRONMENT = 'Production'
      }
    }
    

提交回复
热议问题