0

I have a simple RestAPI which runs on my local and an AWS ECS cloud. I want to run unit tests and integration tests before deploying my app to the cloud. How can I do this with Maven profiles efficiently?

I want to define Maven profiles such as unit-test and integration-test. I want to run these tests using these commands :

mvn clean test -P unit-test
mvn install -P integration-test

Also I have a dev database and production database. When doing integration tests, the app must connect to a seperate test database which creates a need for 2 databases(for dev and prod environments). How can I manage this using Maven profiles?

And I want to define Maven profiles, dev and prod and create application-dev.properties and application-prod.properties so my application knows which configuration to take into account. But I also need a test database for testing, so do I need to create seperate profiles and application.properties files for these tests? (because I need to specify the test database in this application.properties file)

In the end, It seems to me that I need to create a lot of Maven profiles(dev, dev-unit-test,dev-integration-test,prod,prod-unit-test,prod-integration-test).

I got confused and I think there must a better way for managing unit and integration tests accross different environments.

Also, another question : How can I make my application discriminate between unit tests and integration tests regarding to integration-test profile?

EDIT : I figured out how to run unit and integration tests seperately and make my integration and unit tests discriminate the classes(refer to @Liquidpie's answer her How do I get my Maven Integration tests to run). But I still need a good way to define seperate profiles for dev and prod environments as they need to access a test database. How can I achieve that?

cuneyttyler
  • 1,255
  • 2
  • 17
  • 27
  • Is recommended to use surefire plugin for unit tests and failsafe for integration tests, read about that, will be better. – UrbanoJVR Mar 30 '21 at 18:29
  • About the amount of profiles, I don't know another way. My question is, ¿why do you need to separate the execution of integration and unit tests? You can build one dev profile that execute all tests. And, when you want to skip tests, you can skip all tests execuiting with flag -Dmaven.test.skip=true. For example: mvn clean verify -Pdev -Dmaven.test.skip=true. But, in this case, integration and unit tests will be executed (or ignored), both. – UrbanoJVR Mar 30 '21 at 18:35

0 Answers0