-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow certain features and extensions to be turned off while testing #23175
Comments
I have no real solution for you, but this how we do it: We have a So with this setup we have persistence in all tests, but e.g. in What you seem to be looking for sounds a bit like Spring test slices? |
Thanks for the response! persistence/pom.xml <dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jdbc-h2</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-test-h2</artifactId>
<scope>test</scope>
</dependency> persistence/.../resources/application.properties
@QuarkusTest
@QuarkusTestResource(H2DatabaseTestResource.class)
class CARootCreateControllerImplTest {
@Test
void handleRequest() {
}
} My only doubt is the procedure: why do I need a database set up to run unit tests? Quarkus solution is more similar to an integration test... |
You have a point there. IIRC, being able to kinda "exclude" features (similar to test slices) was asked for a while ago. What you could do if you really want plain unit tests is to omit |
@geoand @stuartwdouglas maybe it's time to revist #12512. |
You are correct, I have tried to test using bare junit5 solution but how can I inject beans in my services? The workaround using the h2 database works even because my code architecture extracts business logic from the DAO layer to the Repository layer, so I don't need to create tables in the h2 DB. DAO layer will be tested in the next pipeline layer. However the problem still remains because more tests will be added, more slow became the build. |
If you want to use CDI in unit tests without |
I don't want to reinvent the wheel. I only think that quarkus should split integration tests and unit tests, |
The big question with this is what is considered unit vs what is considered integration, e.g. some people will still want the database connection but not the HTTP server, while others will only want CDI. Basically for every extension we would need to go through and make an arbitrary decision on what is actually started in unit tests, and it will never really be 100% right. Something we could potentially do is allow certain features and extensions to be turned off. |
Yes, I agree with this concept. As I said earlier, I'm not a purist or Taleban of unit testing. If anyone wants to use a DB in unit testing it's ok for me. No problem. Assumption: I want to add unit testing to my code. Great!
If you think of this scenario, who wants to add unit testing without a database will be penalized. So, it is ok for quarkus to provide a method to run unit test with a database easily, but i think that must be a method to run unit tests without a database. |
I totally agree with this and IMHO we should not be trying to make such guesses.
Yeah, that sounds reasonable |
FTR: I rescoped this issue to be in line with the latest state of the discussion. |
Hi. We are forced to omit @QuarkusTest, @QuarkusUnitTest because of this. We extend third-party application, create new extension based on extensions of the application and it uses quarkus features(arc container, security etc). So our modules have dependency on the third-party extensions, all beans of the extensions are loaded during our Unit test and so fail. In order to resolve CDI issues, we use quarkus/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/ArcTestContainer.java Line 51 in 5cd42e4
Serious problem is raised during unit tests of authorization. We have own authorization for quarkus application. When spring was used, we just used |
@voronovmaksim can you please expand a little on your use case? It sounds somewhat similar to what I had proposed in #14927 (comment) |
Thanks a lot @geoand. My use case is like use case of issue specified by you. I run unit test with annotation @QuarkusTest and the unit test is failed because of hibernate Exception, but my test case is just.
Hibernate is not needed in unit test, but it is required in my extension. So it is my problem #14927 (comment) Your proposal #14927 (comment) fits to me. Actually I would like run quarkus test only with specified extension rather than with all extensions that exist in classpath. |
I want to add some unit tests to my Quarkus maven project.
I'm working on a multi-module project structured as:
The test is very simple (empty implementation) and is located in the business module.
When I try to execute my test, quarkus raises an error because agroal (from persistence dependency) needs the database configuration.
First question: how can I run only unit tests (not integration) that don't use the database but only mocks?
However, I have tried to solve the problem by adding a test/resource/application.properties fake configuration and agroal this time found it, raising another error.
This second error is that the Postgres-JDBC driver is not found. This is correct because only the persistence module knows the dependency (using the correct profile).
Second question: if it is not possible to avoid the first question, how can I avoid placing additional dependencies on the module that runs the test?
Expected behavior
I want to run a single unit test (not integration) without database configuration/installation in Quarkus.
Actual behavior
If a single Entity is defined, agroal extension need a configuration to a running database
How to Reproduce?
Add a test like
in a maven module with the agroal extension enabled and no application.properties configured.
Output of
uname -a
orver
Linux 2019-150507 5.10.60.1-microsoft-standard-WSL2
Output of
java -version
OpenJDK 64-Bit Server VM (build 11.0.10+9-Ubuntu-0ubuntu1.20.04, mixed mode)
GraalVM version (if different from Java)
No response
Quarkus version or git rev
2.2.3-Final
Build tool (ie. output of
mvnw --version
orgradlew --version
)Apache Maven 3.6.3
Additional information
No response
The text was updated successfully, but these errors were encountered: