Krash
Krash

Reputation: 45

Running Spock Tests As Part of Jenkins Build

I currently have a build that is automated using Jenkins. The Jenkins build/deploy job builds a Java EAR using maven and then deploys the built EAR to a server.

I want to integrate Spock testing into this build/deploy flow. Once the EAR is build, I want to run the Spock tests against the EAR code. If all the tests pass, then I want to continue with the deployment of the EAR. If one or more of the tests fail, then I want the Jenkins build/deploy job to fail and return an error.

I would also like to display a summary of the test results regardless of whether they are pass or fail.

What changes would I need to make to the Jenkins build/deploy job, the maven project that actually builds the EAR and/or the Spock tests in order to accomplish this?

Upvotes: 0

Views: 1337

Answers (1)

Mark Bramnik
Mark Bramnik

Reputation: 42501

You can see a Spock just as a JUnit extension. And as such, all the tools that help you to run the JUnit powered tests are also applicable to spock.

For example,

  • If you're in Maven, you can use maven-surefire-plugin or maven-failsafe-plugin to run the spock driven tests.
  • If you want to see the results in Jenkins, its possible to use Post Build action and show "Publish Junit test result report"

Now, a confusing part is about the EAR. Tests (Unit and Integration) are usually run before your build is ready. After the EAR is ready, probably you want to run system tests (end-2-end flows) or something. This means that spock/junit/any other framework will have to contact EAR from outside and this in turn means that you'll have to start up the application server and these tests will be like remote clients.

It's possible but the setup will be much more complicated (all databases, the application server itself and so forth) but this is kind of beyond the scope of this question.

Upvotes: 2

Related Questions