1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2025-07-15 01:34:38 +02:00
Files
sap-jenkins-library/test/groovy/util/JenkinsStepRule.groovy

37 lines
901 B
Groovy
Raw Normal View History

2018-02-28 11:54:39 +01:00
package util
import com.lesfurets.jenkins.unit.BasePipelineTest
import java.beans.Introspector
import org.junit.rules.TestRule
import org.junit.runner.Description
import org.junit.runners.model.Statement
2019-03-12 15:48:35 +01:00
2018-02-28 11:54:39 +01:00
class JenkinsStepRule implements TestRule {
2019-03-12 15:48:35 +01:00
2018-02-28 11:54:39 +01:00
final BasePipelineTest testInstance
def step
JenkinsStepRule(BasePipelineTest testInstance) {
this.testInstance = testInstance
}
@Override
Statement apply(Statement base, Description description) {
return new Statement() {
@Override
void evaluate() throws Throwable {
2019-03-12 15:48:35 +01:00
2018-02-28 11:54:39 +01:00
def testClassName = testInstance.getClass().getSimpleName()
def stepName = Introspector.decapitalize(testClassName.replaceAll('Test$', ''))
this.step = testInstance.loadScript("${stepName}.groovy")
2019-03-12 15:48:35 +01:00
2018-02-28 11:54:39 +01:00
base.evaluate()
}
}
}
}