Quarkus unit testing for Panache active record pattern #37293
Unanswered
games1232002
asked this question in
Q&A
Replies: 2 comments 4 replies
-
/cc @FroMage (panache), @loicmathieu (panache) |
Beta Was this translation helpful? Give feedback.
1 reply
-
I don't think that's true. This sounds like the perfect solution in your case. |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I was having issues writing unit tests for my service using Mockito 5.3.1 while trying to move away from Quarkus Dev Services. The concern I have is that in my use case, there is no need to spin up 2 docker containers containing empty MSSQL databases as it's resource intensive.
For greater certainty, "unit tests" that I'm referring to are small tests for basic parts of my code. Since there's no network connectivity required during those tests, my aim is to disable dev services after removing all dependencies on the MSSQL database and tables during unit testing.
I am successful in mocking 90% of my test classes/methods/lines by simply using Mockito, but eventually I will need to mock Panache calls, such as
SomeEntity.listAll()
,SomeEntity.findById
,entity.persist()
whereSomeEntity
is a class with the@Entity
tag and extendsPanacheEntityBase
, whileentity
is an instance ofSomeEntity
.I am aware that it's documented on https://quarkus.io/guides/hibernate-orm-panache#using-the-active-record-pattern that we can make use of
PanacheMock
, but, correct me if I'm wrong, PanacheMock require the use of dev services.Since I am using Mockito >= 3.4.0, I have also attempted to use StaticMock by following this guide: https://www.baeldung.com/mockito-mock-static-methods to try and mock the entity class and methods, such as this:
But that always result in the throwing of
MissingMethodInvocationException
at thewhen
line.After a lot of searching online, and trying different combinations, including reading the following resources:
I am still unable to find a way that I can create unit tests without spinning up 2 empty MSSQL database in containers.
Can someone help?
Beta Was this translation helpful? Give feedback.
All reactions