Skip to content

Instantly share code, notes, and snippets.

@solvingj
Created June 24, 2020 13:48
Show Gist options
  • Select an option

  • Save solvingj/87851300eb97e5aaab524d3e12eee956 to your computer and use it in GitHub Desktop.

Select an option

Save solvingj/87851300eb97e5aaab524d3e12eee956 to your computer and use it in GitHub Desktop.
JPU setup error
package demo.ci.arg
import com.lesfurets.jenkins.unit.declarative.DeclarativePipelineTest
import org.junit.Before
import org.junit.jupiter.api.Test
import static com.lesfurets.jenkins.unit.global.lib.LibraryConfiguration.library
import static com.lesfurets.jenkins.unit.global.lib.ProjectSource.projectSource
class ConanArgsJPUSpec extends DeclarativePipelineTest {
@Override
@Before
void setUp() throws Exception {
super.setUp()
def library = library().name('demo_jenkins_library')
.defaultVersion('<notNeeded>')
.allowOverride(true)
.implicit(true)
.targetPath('<notNeeded>')
.retriever(projectSource())
.build()
helper.registerSharedLibrary(library)
}
@Test
void should_execute_without_errors() throws Exception {
setUp() // I should not have to do this. super.setup() in setup() should be enough
// If i remove, I get error: Helper is not initialized: Call setUp() before tests.
File jenkinsfile = new File('test/resources/jenkinsfiles/Jenkinsfile')
def script = loadScript(jenkinsfile.path)
runScript(script)
printCallStack()
}
}
@stchar

stchar commented Jul 2, 2020

Copy link
Copy Markdown

Unless some assertions depends on junit4 but it's not a big deal to override it

@solvingj

solvingj commented Jul 2, 2020

Copy link
Copy Markdown
Author

Ok, yes, it's JUnit 5. I had no idea there was no @Before. That seems to explain the confusion.

I just tried and added:

    @BeforeEach
    void jpuJunit4Setup(){
        setUp()
    }

As a hacky workaround and now i don't need to call setUp() in all my tests anymore. Thanks!

@stchar

stchar commented Jul 2, 2020

Copy link
Copy Markdown

cool, good to know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment