1

如果任何特定的单元测试执行时间(不是摘要测试运行时间)超过某个合理的限制,比如两秒,我希望我的构建失败。我正在使用 MSTest。

谢谢!

4

1 回答 1

0

使用该timeout块创建超时故障。这是 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"
    }
}
于 2016-05-18T14:46:59.423 回答