I have this Jenkins Unit Test folder structure: enter image description here Code looks like this:
package com.db
import com.lesfurets.jenkins.unit.BasePipelineTest
import org.junit.Before
import org.junit.Test
class TestExample extends BasePipelineTest{
@Before
@Override
void setUp() throws Exception{
super.setUp()
helper.registerAllowedMethod('git',[String])
binding.setVariable('someInstance',[
field: 'value',
someMethod: { return ''}
])
}
@Test
void should_execute_without_errors() throws Exception{
def script = runScript("Jenkinsfile")
printCallStack()
assertJobStatusSuccess()
}
@Test
void should_execute_with_errors() throws Exception{
def script = runScript("Jenkinsfile")
printCallStack()
assertJobStatusUnstable()
}
}
But when it runs I get this message:
Assertion failed:
assert script
|
''
at org.codehaus.groovy.runtime.InvokerHelper.assertFailed(InvokerHelper.java:405)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.assertFailed(ScriptBytecodeAdapter.java:708)
at com.lesfurets.jenkins.unit.PipelineTestHelper.runScript(PipelineTestHelper.groovy:932)
...
According to framework ( https://github.com/jenkinsci/JenkinsPipelineUnit ), the output should have this structure:
exampleJob.run()
exampleJob.execute()
exampleJob.node(groovy.lang.Closure)
exampleJob.load(src/test/jenkins/lib/utils.jenkins)
utils.run()
exampleJob.stage(Checkout, groovy.lang.Closure)
exampleJob.checkout({$class=GitSCM, branches=[{name=feature_test}], extensions=[], userRemoteConfigs=[{credentialsId=gitlab_git_ssh, url=github.com/lesfurets/JenkinsPipelineUnit.git}]})
utils.currentRevision()
utils.sh({returnStdout=true, script=git rev-parse HEAD})
exampleJob.gitlabBuilds({builds=[build, test]}, groovy.lang.Closure)
exampleJob.stage(build, groovy.lang.Closure)
exampleJob.gitlabCommitStatus(build, groovy.lang.Closure)
exampleJob.sh(mvn clean package -DskipTests -DgitRevision=bcc19744)
exampleJob.stage(test, groovy.lang.Closure)
exampleJob.gitlabCommitStatus(test, groovy.lang.Closure)
exampleJob.sh(mvn verify -DgitRevision=bcc19744)