answers Quarkus unit-testing and properties - quarkus

In Qaurkus Project while I am running with an in-memory Profile so runs OK . so I want to run my Junit5 with an in-memory profile, how so i can do this , if anyone has suggestion about this.

Related

Quarkus Liquibase: Runtime-only datasources?

Is there a way to get Liquibase migrations working using Quarkus when the datasources are know only at runtime? For example: One data source per-tenant in a multi-tenant application. The Development, Testing, Staging, and Production environments will all have different datasources.
According to https://quarkus.io/guides/datasource#configuring-multiple-datasources: “Even when only one database extension is installed, named databases need to specify at least one build time property so that Quarkus knows they exist.”
But I’ve found that runtime-only datasources actually work under the dev profile, and only don’t work under the prod profile. So I’m hopeful.
If there’s not a way to do this under the prod profile using Quarkus datasources, then is there a recommended approach?
Minimal reproducible example here: https://github.com/paulmossman/quarkus-liquibase-with-runtime-datasources/blob/main/README.md

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).

start the Spring Boot application once, before Cucumber tests run

I am writing some BDD tests using Cucumber for my Spring Boot application (v2.2.1), and it works OK.
However, I am facing some performance issue, because the application gets started/stopped for every scenario in the feature file : I am using in-memory DB with Liquibase, so for each scenario, this gets executed (takes a few seconds).
Sure, it's currently guaranteed that my scenarios are very well isolated.. Maybe in some cases I will want this behaviour, but right now, most of my feature files would benefit from a one time set up : since each scenario sets up different records (with no overlap) it needs in the in-memory DB, I could theoretically executed my scenarios in parallel on a single Spring Boot application running.
I saw https://blog.codecentric.de/en/2017/02/integration-testing-strategies-spring-boot-microservices-part-2/ , but it requires to have built the application first, then start it from the jar.
Isn't there a way to do the same, but with the application started once from the Cucumber runner ? any example somewhere ?
Thanks to #mpkorstanje link, I was able to find the issue : while trying to replicate the suggestion in my project, I discovered that one of the config that was scanned had a #DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) annotation.. So that was the issue. Now I need to look at a workaround like what is suggested here : #DirtiesContext tears context down after every cucumber test scenario, not class

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?

Integration tests with Arquillian and Arquillian Spring Framework Extension

I would like to set up an infrastructure for integration testing.
Currently we bootstrap tomcat using maven and then execute httpunit tests.
But the current solution has few drawbacks.
Any changes committed to the database need to be rollback manually in the end if the test
Running code coverage on integration test is not straight forward (we are using sonar).
My goals are:
Allow automatic rollback between tests (hopefully using String #transaction and #rollback)
Simple straight forward code coverage
Using #RunWith that will bootstrap the system from JUnit and not externally
Interacting with live servlets and javascript (I consider switching from httpuinit to selenium…)
Reasonable execution time (at least not longer than the existing execution time)
The goals above look reasonable to me and common to many Java/J2ee projects.
I was thinking to achieve those goals by using Arquillian and Arquillian Spring Framework Extension component.
See also https://github.com/arquillian/arquillian-showcase/
Does anyone have and experience with Arquillian and with Arquillian Spring Framework Extension?
Can you share issues best practices and lesson learned?
Can anyone suggest an alternative approach to the above?
I can't fully answer your question. only some tips
Regarding the automatic rollback. In my case. Using liquibase to init the test data on "hsqldb" or "h2" which could be set as in-memory pattern. Then no need to roll back.
For Arquillian. It's a good real testing approach. What i learned is that "Arauillian Spring Framework Extension" is just a extension. You have to bind to a specific container like "jboss, glasshfish,tomcat" to make the test run.
But i don't know how to apply for a spring-based javaSE program which do not need application server support.
My lesson learned is the jboss port conflict. since jboss-dist is set 8080 as default http port. But our company proxy is same as 8080. So i can't use maven to get the jboss-dist artifact.
Hope others can give more info.

Resources