JUnit or QuarkusTest for custom Authenticator class? #11841
Replies: 5 comments 12 replies
-
|
@jfrantzius I believe that we have been using QuarkusTest for the Keycloak Operator. You should be able to find some examples here: https://github.com/keycloak/keycloak/search?q=QuarkusTest @andreaTP @DGuhr certainly know more than me about all the details. |
Beta Was this translation helpful? Give feedback.
-
|
@jfrantzius in the Quarkus integration tests sub-module you can actually find 2 implementations of what you are describing, based on the "raw" Quarkus distribution and on Testcontainers: But those implementations are intended to be used in this very repository, and making them "portable" would require considerable effort. Do you think that using Testcontainers is a viable alternative for you? |
Beta Was this translation helpful? Give feedback.
-
|
As the others have mentioned, please take a look at our testsuite, or e.g. projects like https://github.com/dasniko/testcontainers-keycloak or https://github.com/thomasdarimont/keycloak-project-example :) |
Beta Was this translation helpful? Give feedback.
-
|
Thank you @abstractj , @andreaTP and @DGuhr for your answers. Those solutions all seem to require building and running a Docker image first before running any test. What I was looking for is that I eventually found out how to do this. I modified my pom.xml to include the Keycloak can now be started in Quarkus Dev Mode like this, as documented in https://github.com/keycloak/keycloak/tree/main/quarkus#running-in-keycloak-development-mode : In the log I can see that Keycloak is also picking up my extension Java class, which is great. I haven't written a |
Beta Was this translation helpful? Give feedback.
-
|
@jfrantzius unfortunately, that's not possible atm. I think @thomasdarimont opened up a discussion around this here on the quarkus-dev mailing list, but there was no follow-up, and sadly as of now we didn't come back to that. cc @pedroigor |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
we developed a custom
org.keycloak.authentication.Authenticatorclass, and I am now looking for a way of writing automated tests for it. I looked at https://stackoverflow.com/questions/45492999/how-to-unit-test-a-new-keycloak-authenticator , which takes the road of mocking the inner parts of Keycloak that are required for the class to operate. That seems risky to me, as it is based on a lot of assumptions on the inner workings of Keycloak, which may simply differ from runtime reality, and which are also quite tedious to find out plus having the risk to stumble over some static Keycloak method that cannot be mocked.Now that Keycloak has moved to Quarkus, and having worked with
QuarkusTesta lot, I wonder if somebody already has managed to write aQuarkusTestthat runs Keycloak e.g. against an in-memory database, so a custom class can be tested inside of a "real" running Keycloak?I found QuarkusTest to be very very helpful in testing Quarkus applications, as they allow to easily test logic in the context a whole runtime stack, avoiding lots of mocking and the mistakes that may come with it. I think it would be very helpful for the development of custom Keycloak extensions if they could be tested using QuarkusTest!
Cheers to the Keycloak community,
Jörg
Beta Was this translation helpful? Give feedback.
All reactions