github.com/ouraigua/jenkins-library@v0.0.0-20231028010029-fbeaf2f3aa9b/test/groovy/util/JenkinsStepRule.groovy (about) 1 package util 2 3 import com.lesfurets.jenkins.unit.BasePipelineTest 4 5 import java.beans.Introspector 6 7 import org.junit.rules.TestRule 8 import org.junit.runner.Description 9 import org.junit.runners.model.Statement 10 11 12 class JenkinsStepRule implements TestRule { 13 14 final BasePipelineTest testInstance 15 16 def step 17 18 JenkinsStepRule(BasePipelineTest testInstance) { 19 this.testInstance = testInstance 20 } 21 22 @Override 23 Statement apply(Statement base, Description description) { 24 return new Statement() { 25 @Override 26 void evaluate() throws Throwable { 27 28 def testClassName = testInstance.getClass().getSimpleName() 29 def stepName = Introspector.decapitalize(testClassName.replaceAll('Test$', '')) 30 this.step = testInstance.loadScript("${stepName}.groovy") 31 32 base.evaluate() 33 } 34 } 35 } 36 }