Using JenkinsPipelineUnit to test pipeline is returning error with import in the script

217 Views Asked by At

The pipeline I'm trying to execute with JenkinsPipelineUnit have some imports and full path classes.

import org.jenkins.plugins.lockableresources.LockableResourcesManager

(...)

} catch (org.jenkinsci.plugins.workflow.steps.FlowInterruptedException e) {

(...)

After I declare the test (using Java/Junit5) with:

@BeforeEach
void setup() throws Exception {
    setUp();
    
    Binding binding = getBinding();
    binding.setVariable("MY_VARIABLE", "MY_VALUE");
    (...)

    PipelineTestHelper helper = getHelper();
    helper.registerAllowedMethod("getFreeResourceAmount", List.of(String.class), null);
    (...)

}

@Test
void test1() {
    Script script = loadScript("/path/to/jenkinsfile");
    script.run();
    assertJobStatusSuccess();
}

How can I use the helper or other component to allow the test to resolve classes like?

org.jenkins.plugins.lockableresources.LockableResourcesManager
hudson.tasks.test.AbstractTestResultAction

0

There are 0 best solutions below