4

I have a multi-module project with unit tests and integration tests. We're using Jenkins for our pipeline:

  1. build + unit tests
  2. deploy to staging
  3. integration tests against staging.

What I want to achieve is:

  • Step one - build + unit test + package + install
  • Step two - deploy already packaged artifacts
  • Step three - run integration tests (without building all over again)

Step three starts from a clean checkout, so there isn't even a target folder.

Edit - the integration test run inside a profile, so they don't run during the first build

What I want to achieve is to run the integration tests (step three) without compiling the code.

If I use mvn failsafe:integration-tests it says that there aren't any tests (obviously because it doesn't find any artifact).

When I add dependenciesToScan it says that it doesn't find the junit provider (groups/excludedGroups require TestNG, JUnit48+ or JUnit 5 on project test classpath).

Can someone help on how to implement running the tests when the jars are in the local repo, without compiling?

Issahar Weiss
  • 203
  • 1
  • 10
  • If you run `mvn install` the integration test phases are already done...I don't understand what kind of problem you are trying to solve? – khmarbaise Aug 19 '18 at 15:09
  • Running in two steps - the first step is without integration tests, and the other one only integration tests. – Issahar Weiss Aug 19 '18 at 15:10
  • Sorry but this is what I've read in your post...the question is why do you need that? Or what kind of problem you have which you would like to solve with this? Why not running the unit tests and afterwards integration test as Maven already defines via it's life cycle? – khmarbaise Aug 19 '18 at 15:14
  • 1
    Edited and added the use case. Sorry for not explaining before. – Issahar Weiss Aug 19 '18 at 15:15
  • Can you explain what you mean by `deploy to staging`? Is this an environment where you deploy your artifact to a application sever or a like? What kind of project is this? Spring, Spring Boot? Or classical JEE ? – khmarbaise Aug 19 '18 at 15:15
  • This is a classic JEE (using dropwizard). Deploy to staging is uploading the artifacts to AWS, and updating our environments there. Then we have a lot of integration tests, calling our API on the staging env on AWS – Issahar Weiss Aug 19 '18 at 15:18
  • Hm..dropwizard is microservice framework and has not really a relation to JEE (EJB etc.)...How they are deployed on AWS? EC2 instances? Apart from that running the integration tests should be done before deploying into an environment..maybe you have some integration tests which are really only working in your target environment which usually is an indicator for infrastructure tests than integration tests...Testing REST services can be done without deploying to an environment? – khmarbaise Aug 19 '18 at 15:43

2 Answers2

5

In maven there is a concept of phases attached to a lifecycle.

The plugins goals are attached to phases.

See here for more information

When you run:

mvn verify

Its actually running all phases up-to (including) verify and invoke all the plugins attached to these phases.

So if you want to skip running integration tests during the mvn verify you can do:

mvn verify -DskipITs=true 

Now if you want to run only integration tests, you can just invoke failsafe plugin without calling a full "cycle" (compilation, unit tests, etc.):

mvn failsafe:integration-test

Of course this assumes that the compilation has been already done, and the binary compiled files already reside in the target directory

Mark Bramnik
  • 39,963
  • 4
  • 57
  • 97
1

I did something similar several times. My standard solution is to put the system test suite in a separate module next to the actual artifact in the same repository.

Steps one and two would happen only within the service module, while step three happens in the system-test module running mvn verify.

Michael
  • 2,443
  • 1
  • 21
  • 21
  • That could actually work! We do have SystemTests, and now I figured out how I can use it in order to achieve what I wanted! Thank you very much! – Issahar Weiss Aug 20 '18 at 23:24