How can I change the profile for running an integration test? - quarkus

I'm executing a test using #QuarkusIntegrationTest. Obviously, this is run with the prod profile, not the test profile.
How can I activate the test profile in a simple way for my integration test? Right now, I'm forced to create a separate QuarkusTestProfile and annotate it with #TestProfile.

You can you use the quarkus.test.native-image-profile=test property

Related

Run Spring Boot application with test application.properties

I've just installed Cypress to run e2e tests and that requires my Spring Boot app running so it can plug into the browser to run tests.
I already have an application.properties file under test/resources which creates an H2 memory database populated from a test/resources/data.sql to run my unit and integration tests.
I want to start my app using those test resources so I can run Cypress tests with my testing environment, is that poosible?
I tried changing SPRING_PROFILES_ACTIVE env variable to test but it doesn't take my config files under the test folder, what can I do?
test/resources/application.properties is, as far as I understand it, purely for use in (unit/integration/service) tests that live in test/.
Try creating an additional application-test.properties file in main/resources. This should be used when you have the test Spring profile activated (although it might be better to choose another name for the profile to avoid confusion).

Best way to decouple integration test cases from build (gradle spring-boot)

I am working on a large project and need to offer users the ability to optionally enable or disable local integration test cases ( For pipeline, test cases must be enforced).
First of all, welcome to the community.
Next, you can modify the test task inside the build.gradle file or maybe add a new task called integrationTest and implement your custom logic there.
As an instance, you can check this gist on Github: Separating tests from integration tests with Gradle
You can also use #Profile annotation to your integration test classes and run your tests with different profiles. You can read more about profiles using the following link: Spring Profiles

Springboot and maven: how to launch unit tests automatically with two profiles

This question is the continuation of question "SpringBoot: how to run tests twice, with two different config files".
I use to compile my project using mvn clean install. Doing that, maven also launches my unit tests and I immediately knows whether my development is correct.
I am actually working on a module that embeds a JMS connection. my module supports two JMS buses: EMS and AMQ. The bus to be used is specified in the configuration of my module
As a consequence, I need to create two profiles, one for EMS and one for AMQ.
However, when I launch my mvn clean install I want that maven launches automatically the tests using the two profiles, not only one; I don't want to have to launch it twice: mvn clean test -Dspring.profiles.active=ems ; mvn clean test -Dspring.profiles.active=amq
Thank you for help
You can pass the two profiles separated by a comma:
mvn clean install -Dspring.profiles.active=ems,amq
And then you'll have two active profiles:
The following profiles are active: ems,amq
I think that there is a miss-understanding; It seems that when I run my tests with spring.profiles.active=ems,amq:
all tests are launched one time
both profiles are enabled
What I want is different:
launch all tests TWO TIMES
first time with ems (and only ems) profile enabled
second time with amq (and only amq) profile enabled
For the moment, I do not succeed to find a solution; evey clue is welcome
Regards
I found a solution for my issue; a kind of trick based on:
overloading the SpringJUnit4ClassRunner
redefining the run() method in order to:
call force the use of the first profile
call the origial run() method
do the same with the other profile
public class MultiProfileTestRunner extends SpringJUnit4ClassRunner {
...
public void run(RunNotifier notifier) {
System.setProperty("spring.profiles.active", "ems");
super.run(notifier);
System.setProperty("spring.profiles.active", "amq");
super.run(notifier);
}
Between both calls to super.run() we have to 'force' Spring to reload its context, otherwize the profile change is not taken into account
I did it by using the annotation #DirtiesContext(classMode = AFTER_CLASS) on my tests
You can also specify in the src/test/resources/application.properties specific properties that apply every time Spring tests are run. Seems cleaner to me than specifying them on Maven command line. For your case :
spring.profiles.active=ems,amq

Multiple Profiles For Spring Integration Tests?

I need different profiles for a few things. First we have the issue of my databases. When I run local tests I expect to use one datasource. When I run an acceptance profile (for a CI acceptance build), I expect to use a different datasource. Finally, when I run acceptance not in test I expect to use a third datasource. How I imagined this would work is.
/src/main/resources/application.properties
/src/main/resources/application-acceptance.properties
/src/test/resources/application-test.properties
/src/test/resources/application-acceptance-test.properties
However when I run mvn clean install -Dspring.profiles.active=acceptance it does not run the application-accepatnce-test.properties.
Finally, I would like to be able to run a mvn install while running the tests but not the integrations test. For this I imagine I would add a -Dspring.profiles.active=nointegration and then simply add an #ActiveProfiles('!nointegration') on the integration tests.
I've had no luck with either of these. Is it even possible to get profiles on test runs?
If it helps I am using Spring Boot 1.3.0.RELEASE.
EDIT:
On my integration tests I have #ActiveProfiles("test"). Is there any way to generate the profile here based on the java-opt spring.profiles.active?

maven cargo integration test - how to get cargo.hostname or profile?

I'm using Maven 2 w/ cargo to deploy to different remote tomcats depending on the maven profile used.
I also have integration tests (junit w/ remote webservice calls) that I would like to automatically run.
Question: How do I setup my test code to be able to read either the cargo.hostname (preferred, changed property value based on maven profile) or the maven profile actived so it knows which url to go run the tests against?
Specifically, this is in java in the test case.
Thanks!
Either you define a fixed value for the cargo.hostname (not the best; but sometimes it workds well, cause using a fixed test server) or better define an appropriate property in Maven for it and put the information also into a properties file which will be filtered by the build process in the src/test/resources folder which can be read before the real integration tests.

Resources