1

I would like to fail my builds if ANY particular unit test execution time (not the summary tests run time) exceeds certain reasonable limit, say two seconds. I am using MSTest.

Thanks!

dmitshap
  • 31
  • 4

1 Answers1

0

Use the timeout block to create a timeout failure. Here is an example from the Jenkins CI Jenkinsfile:

// We're wrapping this in a timeout - if it takes more than 180 minutes, kill it.
timeout(time: 180, unit: 'MINUTES') {
    // See below for what this method does - we're passing an arbitrary environment
    // variable to it so that JAVA_OPTS and MAVEN_OPTS are set correctly.
    withMavenEnv(["JAVA_OPTS=-Xmx1536m -Xms512m -XX:MaxPermSize=1024m",
                  "MAVEN_OPTS=-Xmx1536m -Xms512m -XX:MaxPermSize=1024m"]) {
        // Actually run Maven!
        // The -Dmaven.repo.local=${pwd()}/.repository means that Maven will create a
        // .repository directory at the root of the build (which it gets from the
        // pwd() Workflow call) and use that for the local Maven repository.
        sh "mvn -Pdebug -U clean install ${runTests ? '-Dmaven.test.failure.ignore=true -Dconcurrency=1' : '-DskipTests'} -V -B -Dmaven.repo.local=${pwd()}/.repository"
    }
}
walsht
  • 196
  • 1
  • 10
  • This is the overall build time..not specific to Unit-Tests. – granadaCoder May 18 '16 at 19:35
  • Anything can go into the `timeout() { }`. Instead of having a timeout for the whole maven lifecycle you could use the MSTest plugin to run the unit tests. If the OP wants to have a timeout on the individual tests instead of the time it takes to run all tests, that would be specific to MSTest. – walsht May 18 '16 at 20:39