mirror of
https://github.com/SAP/jenkins-library.git
synced 2024-12-12 10:55:20 +02:00
add JenkinsStepRule
This commit is contained in:
parent
efafd9a44a
commit
be26c8dc1e
32
test/groovy/util/JenkinsStepRule.groovy
Normal file
32
test/groovy/util/JenkinsStepRule.groovy
Normal file
@ -0,0 +1,32 @@
|
||||
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
|
||||
|
||||
class JenkinsStepRule implements TestRule {
|
||||
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 {
|
||||
def testClassName = testInstance.getClass().getSimpleName()
|
||||
def stepName = Introspector.decapitalize(testClassName.replaceAll('Test$', ''))
|
||||
this.step = testInstance.loadScript("${stepName}.groovy")
|
||||
base.evaluate()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user