Skip to content
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

Preview - Keycloak Test Framework #488

Merged
merged 1 commit into from
Nov 14, 2024
Merged

Preview - Keycloak Test Framework #488

merged 1 commit into from
Nov 14, 2024

Conversation

lhanusov
Copy link
Contributor

@lhanusov lhanusov commented Aug 29, 2024

Closes #32399

@lhanusov lhanusov force-pushed the 32399 branch 3 times, most recently from 2d89793 to 46b3979 Compare August 29, 2024 15:16
Copy link

@vaceksimon vaceksimon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Content-wise I don't find it missing anything. It's great as it is now.
I ran it through a grammar checker and included some of my rephrasing suggestions.
Feel free to ignore any of it.

blog/2024/preview-keycloak-test-framework.adoc Outdated Show resolved Hide resolved
blog/2024/preview-keycloak-test-framework.adoc Outdated Show resolved Hide resolved
blog/2024/preview-keycloak-test-framework.adoc Outdated Show resolved Hide resolved
blog/2024/preview-keycloak-test-framework.adoc Outdated Show resolved Hide resolved
blog/2024/preview-keycloak-test-framework.adoc Outdated Show resolved Hide resolved
blog/2024/preview-keycloak-test-framework.adoc Outdated Show resolved Hide resolved
blog/2024/preview-keycloak-test-framework.adoc Outdated Show resolved Hide resolved
blog/2024/preview-keycloak-test-framework.adoc Outdated Show resolved Hide resolved
blog/2024/preview-keycloak-test-framework.adoc Outdated Show resolved Hide resolved

== Brighter Future?

Keycloak team had started a https://github.com/orgs/keycloak/projects/42[joint effort] between the engineering and quality engineering people to design a new test framework (May 2024). It had been initiated with a prototype to verify if our thoughts were feasible. The prototype was based on the _JUnit5_ testing framework, specifically to implement _JUnit5_ callback classes which extend the default test lifecycle functionality and provide custom inject annotations, like _@KeycloakIntegrationTest_, _@InjectWebDriver_ or _@InjectRealm_.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just say Keycloak team - engineering and quality engineering is a RH thing, and we're all just the Keycloak team :)

== Are you curious about where to start?
We suggest reading the https://github.com/keycloak/keycloak/blob/main/test-framework/README.md[user guide], which will provide a basic overview of how the framework works and should be used. If this is not enough, you can also check https://github.com/keycloak/keycloak/tree/main/test-poc/examples[examples module].

For extension developers we recommend to look into the showcase example on how to start _Keycloak_ with their custom provider - link.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a note that we need to update this before publishing the blog


For extension developers we recommend to look into the showcase example on how to start _Keycloak_ with their custom provider - link.

Once you find a bug, want to discuss something, or propose a new enhancement, please follow this GitHub feedback https://www.github.com/discussion#blabla[discussion] link.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a note that we need to update this before publishing the blog


== Coming Soon

Preview - https://github.com/keycloak/keycloak/tree/main/test-framework[_Keycloak Test Framework_] will be introduced in _Keycloak Nightly_ builds. We plan to add more features, which will cover 80% of functionalities currently available in the https://github.com/keycloak/keycloak/tree/main/testsuite[integration test suite]. We also plan to introduce some new concepts, e.g. _@KeycloakTest_ annotation, which will add an option to test providers without the _Keycloak_ server running. It should be based on the _KeycloakSession_ class. Other interesting features should be parallel execution on a GitHub runner, adding a custom extension to a Keycloak server, or enabling a Keycloak cluster setup.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is available, not will be ;)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove 80%, and say something like cover enough for most tests...


== Brighter Future?

Keycloak team had started a https://github.com/orgs/keycloak/projects/42[joint effort] between the engineering and quality engineering people to design a new test framework (May 2024). It had been initiated with a prototype to verify if our thoughts were feasible. The prototype was based on the _JUnit5_ testing framework, specifically to implement _JUnit5_ callback classes which extend the default test lifecycle functionality and provide custom inject annotations, like _@KeycloakIntegrationTest_, _@InjectWebDriver_ or _@InjectRealm_.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The board is private, and not visible to everyone. So we either remove the link, or cleanup the board and make it public


For extension developers we recommend to look into the showcase example on how to start _Keycloak_ with their custom provider - link.

Once you find a bug, want to discuss something, or propose a new enhancement, please follow this GitHub feedback https://www.github.com/discussion#blabla[discussion] link.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Once you find a bug, want to discuss something, or propose a new enhancement, please follow this GitHub feedback https://www.github.com/discussion#blabla[discussion] link.
If you find a bug, want to discuss something, or propose a new enhancement, please follow this GitHub feedback https://www.github.com/discussion#blabla[discussion] link.


The idea to replace the current https://github.com/keycloak/keycloak/tree/main/testsuite[test suite] has been on the table for multiple years. Initially, it was meant to be only a refactoring of the current approach on how to write tests, but after a few internal discussions and refactor updates it turned out a new test suite, based on a https://github.com/keycloak/keycloak/tree/main/test-framework[new framework] would be a better solution.

It would be good to mention a few drawbacks, that stand out when working with the current https://github.com/keycloak/keycloak/tree/main/testsuite[test suite]. First of all, is the complexity of various configurations and additions made on top of the https://arquillian.org/[_Arquillian framework_]. These changes make the test suite powerful, but the cons is that without proper documentation for beginners is almost unreadable. The second thing has the same importance, the _Arquillian framework_ is not fully supported anymore. Other things to mention are a complicated execution system, where you want to specify what exactly should be tested, then abstract classes with shared configurations, missing the option to add a custom extension, and last but not least, the massive amount of tests without knowledge if they are needed anymore.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not convinced about the statement the massive amount of tests without knowledge if they are needed anymore. There may be some tests not needed, but probably not a massive amount. Perhaps just drop this?


== Brighter Future?

The Keycloak team began an effort to design a new test framework in May 2024. It started with a prototype to verify if our ideas were feasible. The prototype was based on the https://junit.org/junit5/[_JUnit5_ testing framework], specifically to implement https://junit.org/junit5/docs/current/user-guide/#extensions-lifecycle-callbacks[_JUnit5_ callback classes] which extend the default test lifecycle functionality and provide custom inject annotations, like _@KeycloakIntegrationTest_, _@InjectWebDriver_ or _@InjectRealm_.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The Keycloak team began an effort to design a new test framework in May 2024. It started with a prototype to verify if our ideas were feasible. The prototype was based on the https://junit.org/junit5/[_JUnit5_ testing framework], specifically to implement https://junit.org/junit5/docs/current/user-guide/#extensions-lifecycle-callbacks[_JUnit5_ callback classes] which extend the default test lifecycle functionality and provide custom inject annotations, like _@KeycloakIntegrationTest_, _@InjectWebDriver_ or _@InjectRealm_.
The Keycloak team began an effort to design a new test framework in May 2024. It started with a prototype to verify if our ideas were feasible. The prototype was based on the https://junit.org/junit5/[_JUnit5_ testing framework], specifically to implement https://junit.org/junit5/docs/current/user-guide/#extensions-lifecycle-callbacks[_JUnit5_ callback classes] which extend the default test lifecycle functionality and provide custom inject annotations, like _@KeycloakIntegrationTest_, _@InjectWebDriver_ or _@InjectRealm_.

Perhaps writing something like The prototype is an JUnit 5 Extension...

Comment on lines 16 to 21
For our purpose, we have https://github.com/keycloak/keycloak/blob/main/test-framework/core/src/main/java/org/keycloak/test/framework/KeycloakIntegrationTestExtension.java[implemented] these three callback classes:
----
BeforeEachCallback
AfterEachCallback
AfterAllCallback
----
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would drop this, folks just need to know it's a JUnit 5 extension that is automatically added when you add the dependency; they don't need to know the internals.

AfterAllCallback
----

After a successful test round, we've continued with a proof of concept extending features list to support multiple server modes, different databases and _WebDrivers_, clients and users setup, _SmallRye_ configuration support, _OAuthClient_ based on https://connect2id.com/products/nimbus-oauth-openid-connect-sdk[_Nimbus SDK_] (this feature is a preview only) etc. The full list of currently implemented features can be found here in the https://github.com/keycloak/keycloak/tree/main/test-framework/core/src/main/java/org/keycloak/test/framework/annotations[annotations package]. It is already present in the main branch and _Keycloak_ nightly builds.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The full list of features in the annotations package isn't the best way to list the features; and now that we split it up into multiple modules it doesn't list all annotations.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just do a bullet point list of features?

Comment on lines 32 to 34
== Coming Soon

Main plan is to cover enough features for most functionalities currently available in the https://github.com/keycloak/keycloak/tree/main/testsuite[integration test suite]. Next future step shall be to introduce some new concepts, e.g. _@KeycloakTest_ annotation, which will add an option to test providers without the _Keycloak_ server running. It should be based on the _KeycloakSession_ class. Other interesting features should be https://junit.org/junit5/docs/current/user-guide/#junit-platform-suite-engine[_JUnit5_ test suites], parallel execution on a GitHub runner or enabling a Keycloak cluster setup.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
== Coming Soon
Main plan is to cover enough features for most functionalities currently available in the https://github.com/keycloak/keycloak/tree/main/testsuite[integration test suite]. Next future step shall be to introduce some new concepts, e.g. _@KeycloakTest_ annotation, which will add an option to test providers without the _Keycloak_ server running. It should be based on the _KeycloakSession_ class. Other interesting features should be https://junit.org/junit5/docs/current/user-guide/#junit-platform-suite-engine[_JUnit5_ test suites], parallel execution on a GitHub runner or enabling a Keycloak cluster setup.
== Next steps
We already have enough capabilities in the new test framework to start migrating some tests from the old testsuite; and in fact already have our very first test migrated. We plan to migrate one package at a time from the old testsuite starting with `admin` tests, then moving on to `forms` and `oauth` packages. As we are doing this we will expand on the capabilities of the test framework.
Some features we know will be coming soon include:
* An easier way to deploy custom providers, not requiring a Maven build of the provider first
* Improved logging, making it easy to configure logging from tests as well as Keycloak
* Easy testing of OAuth and OpenID Connect, including a mock application
* Extension to allow running code on the tested server when it's not possible to easily test through only remote interfaces

We also have some more long term plans to deliver:

  • Provider tests that can be used to easily test a provider by invoking the provider directly
  • Parallel execution of tests, to take full advantage of multiple cores to reduce test execution time

@@ -0,0 +1,67 @@
:title: "Writing new tests has never been easier than before." Keycloak Test Framework
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This title won't show very nicely on the website or feeds

Suggested change
:title: "Writing new tests has never been easier than before." Keycloak Test Framework
:title: Introducing the Keycloak Test Framework

:title: "Writing new tests has never been easier than before." Keycloak Test Framework
:date: 2024-11-14
:publish: true
:author: Lukas Hanusovsky, Stian Thorgersen
Copy link
Contributor

@stianst stianst Nov 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You get the full creds for this one; I just suggested some minor changes ;)

Suggested change
:author: Lukas Hanusovsky, Stian Thorgersen
:author: Lukas Hanusovsky

Signed-off-by: Lukas Hanusovsky <[email protected]>
Co-authored-by: Stian Thorgersen <[email protected]>
@stianst stianst merged commit ddbcf6a into keycloak:main Nov 14, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Blog post to introduce test framework
3 participants