Andrey Ershov
Andrey Ershov

Reputation: 1803

Jenkins job dsl and MSTest integration

Jenkins Job DSL plugin is an extremely nice way to store CI config in repo and vary it from branch to branch.

The question is - is there a natural or close to natural way to run MSTest tests, parse results and display them.

Right now I do a powershell call, but that gives me only logs, not UI integration.

def testSomeProjectJob =  job(testSomeProjectJobName) {
    steps { 
      powerShell("& ${vstest} '${root}/SomeProject/SomeProject.Tests/bin/Debug/SomeProject.Tests.dll' ")
    }
}

May be there is a publisher or a trick with templating, or some tips of writing a plugin to JOB DSL for that


UPD: final script template for MSTest and VSTest using @daspilker answer, jenkins xUnit Plugin and archiveXUnit

  job('RunTests') {
      steps {
           // VSTEST
           powerShell("& ${vstest} 'path/to/Tests.dll' /logger:trx ")
           // Or MSBUILD
            powerShell("& ${msbuild} /testcontainer:'path/to/Tests.dll' ")
      }
      publishers {
        archiveXUnit {
          msTest {
            pattern('**/*.trx')
            // deleteOutputFiles()
          }
        }
      }
    }

Upvotes: 2

Views: 935

Answers (2)

Tanner Watson
Tanner Watson

Reputation: 270

Its for VSTest but I had to end up using the configure block to be able to use it in the DSL jobs.

static Closure useVsTest(List<String> dlls) { return { it / 'builders' << 'org.jenkinsci.plugins.vstest__runner.VsTestBuilder' { vsTestName 'VS 14.0' testFiles dlls.join('\n') settings '' testCaseFilter '' enablecodecoverage false useVsixExtensions true platform 'x86' otherPlatform '' framework 'framework45' otherFramework '' logger 'trx' otherLogger '' cmdLineArgs '/TestAdapterPath:"."' failBuild true } } }

Upvotes: 2

daspilker
daspilker

Reputation: 8194

Using a PowerShell step is a good start. Install the xUnit Plugin to parse and display the results. It can parse all sorts of test results including MSTest. And you can use the DSL to configure the plugin.

Example:

job('example') {
  steps {
    powerShell('...')
  }
  publishers {
    archiveXUnit {
      msTest {
        pattern('path/to/test/results')
      }
    }
  }
}

Upvotes: 5

Related Questions