JenkinsPipelineUnit
JenkinsPipelineUnit copied to clipboard
Compatibility with Groovy 4
Jenkins and plugins versions report
Environment
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>jenkins-pipeline-testing</artifactId>
<version>1.0-SNAPSHOT</version>
<repositories>
<repository>
<id>jenkins-ci-releases</id>
<url>https://repo.jenkins-ci.org/releases/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.apache.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>4.0.0</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>com.lesfurets</groupId>
<artifactId>jenkins-pipeline-unit</artifactId>
<version>1.14</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>1.13.1</version>
<executions>
<execution>
<goals>
<goal>execute</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.apache.groovy</groupId>
<artifactId>groovy</artifactId>
<version>4.0.0</version>
<scope>runtime</scope>
</dependency>
</dependencies>
<configuration>
<scripts>
<script>src/main/groovy/Main.groovy</script>
</scripts>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
</project>
What Operating System are you using (both controller, and any agents involved in the problem)?
Fedora 36 java 1.8.0_302
Reproduction steps
I'm trying to run a DeclarativePipelineTest, file is TestDecExample.groovy
import org.junit.Before
import org.junit.Test
import com.lesfurets.jenkins.unit.declarative.*
class TestDecExample extends DeclarativePipelineTest {
// Setup environment for running unit tests
@Override
@Before
public void setUp() throws Exception {
super.setUp()
}
@Test
public void should_execute_without_errors() throws Exception {
def script = loadScript("Jenkinsfile")
script.execute()
assertJobStatusSuccess()
printCallStack()
}
}
The Jenkins file is:
pipeline {
agent none
stages {
stage('Example Build') {
agent { docker 'maven:3-alpine' }
steps {
echo 'Hello, Maven'
sh 'mvn --version'
}
}
stage('Example Test') {
agent { docker 'openjdk:8-jre' }
steps {
echo 'Hello, JDK'
sh 'java -version'
}
}
}
}
Then I run mvn test
, same results with executing the test via Intellij
Expected Results
The test runs and prints if it is successful or not.
Actual Results
groovy.lang.MissingMethodException: No signature of method: com.lesfurets.jenkins.unit.declarative.DeclarativePipelineTest.setUp() is applicable for argument types: () values: []
Possible solutions: setUp(), setUp(), getAt(java.lang.String), tap(groovy.lang.Closure), sleep(long), sleep(long, groovy.lang.Closure)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:72)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuperN(ScriptBytecodeAdapter.java:148)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuper0(ScriptBytecodeAdapter.java:166)
at com.lesfurets.jenkins.unit.declarative.DeclarativePipelineTest.setUp(DeclarativePipelineTest.groovy:17)
at TestDecExample.super$3$setUp(TestDecExample.groovy)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:343)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:328)
at groovy.lang.MetaClassImpl.doInvokeMethod(MetaClassImpl.java:1369)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1103)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuperN(ScriptBytecodeAdapter.java:146)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuper0(ScriptBytecodeAdapter.java:166)
at TestDecExample.setUp(TestDecExample.groovy:10)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
at org.junit.internal.runners.statements.RunBefores.invokeMethod(RunBefores.java:33)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
```
### Anything else?
_No response_
I just tried to reproduce locally by copy/pasting your files into a new, empty project. It worked fine for me, using Ubuntu-ish Linux 21.10 and OpenJDK 1.8.0_312.
With the same pom.xml?
@andrefmarques Yep, copy pasted from the "details" part of the issue description above.
I've tried on Lubuntu 22.04 and got the same issue. BasePipelineTest and BaseRegressionTest are working as expected. Any idea where to look for the cause of this?
Sadly, I'm not certain. I don't use the declarative API for pipelines myself and am not terribly familiar with these test classes.
If you like, I can upload a tarball of the example project based on your above code, just as a sanity check. Would that be useful @andrefmarques ?
Yes, that would be great!
Ok, here's my test project: test-project-thingy.tar.gz
@andrefmarques just do not use Groovy 4. It is GroovyObjectHelper class which fails and which is introduced in version 4.
@grzegorzgrzegorz is right, this is probably a Groovy 4 issue. I've renamed this issue accordingly.
I am testing with Groovy 3.0.11 and everything works well.