-
Notifications
You must be signed in to change notification settings - Fork 226
docs: describe per-test Vaadin configuration for browserless tests #6094
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
Open
mshabarov
wants to merge
3
commits into
main
Choose a base branch
from
docs/browserless-test-configuration
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+147
−0
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
b091a90
docs: describe per-test Vaadin configuration for browserless tests
mshabarov 6ec3a62
docs: note the moved browserless lookup services in the upgrade guide
mshabarov dba4527
docs: list the application context builder configuration methods
totally-not-ai[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
articles/flow/testing/browserless/test-configuration.adoc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| --- | ||
| title: Test Configuration | ||
| page-title: How to configure the Vaadin environment of a browserless test | ||
| description: Set Vaadin application properties, feature flags, and Lookup services for a single test class or test method. | ||
| meta-description: Configure Vaadin application properties, feature flags, and Lookup services for a single browserless test with the BrowserlessTestConfig annotation. | ||
| order: 46 | ||
| --- | ||
|
|
||
|
|
||
| = [since:com.vaadin:vaadin@V25.3]#Test Configuration# | ||
|
|
||
| Some tests need a Vaadin environment configured differently from the rest of the suite: a view behind a feature flag, or a setting such as `devmode.sessionSerialization.enabled`. Annotate the test class, or a single test method, with [annotationname]`@BrowserlessTestConfig`: | ||
|
|
||
| [source,java] | ||
| ---- | ||
| @ViewPackages(classes = CartView.class) | ||
| @BrowserlessTestConfig( | ||
| applicationProperties = "devmode.sessionSerialization.enabled=true", | ||
| featureFlags = "myExperimentalFeature") | ||
| class CartViewTest extends BrowserlessTest { | ||
|
|
||
| @Test | ||
| void experimentalCheckoutIsShown() { | ||
| // The feature flag is enabled for this test | ||
| } | ||
|
|
||
| @Test | ||
| @BrowserlessTestConfig(featureFlags = "myExperimentalFeature=false") | ||
| void fallbackCheckoutIsShown() { | ||
| // The same class, with the flag off for this method only | ||
| } | ||
| } | ||
| ---- | ||
|
|
||
| Each setting applies to the Vaadin environment created for the annotated test, so there is nothing to reset afterwards, and nothing leaks into the next test. | ||
|
|
||
|
|
||
| == Settings | ||
|
|
||
| [cols="1,2"] | ||
| |=== | ||
| | Attribute | Description | ||
|
|
||
| | [propertyname]`applicationProperties` | ||
| | `name=value` pairs applied to the Vaadin deployment configuration, such as `"devmode.sessionSerialization.enabled=true"`. The value is everything after the first `=`, so a value can itself contain `=`. The properties are set before the servlet starts, so code that runs at startup, such as a [interfacename]`VaadinServiceInitListener`, already sees them. | ||
|
|
||
| | [propertyname]`featureFlags` | ||
| | Either a feature identifier, to enable the feature, or an `id=true\|false` pair. These flags override the [filename]`vaadin-featureflags.properties` file and the `vaadin.experimental.*` system properties. Toggling a flag this way needs no development mode and writes nothing into the project folder. An unknown identifier fails with an error that lists the available flags. | ||
|
|
||
| | [propertyname]`lookupServices` | ||
| | Implementation classes registered with the Vaadin [classname]`Lookup`, such as an [interfacename]`InstantiatorFactory` or a [interfacename]`ResourceProvider`. | ||
| |=== | ||
|
|
||
| The `browserless` application property itself stays enforced and cannot be overridden. | ||
|
|
||
|
|
||
| == Merging Class and Method Configuration | ||
|
|
||
| Every annotation a test inherits contributes to the configuration, rather than being shadowed by the nearest one. The closer a declaration is to the test method, the higher it ranks: the method first, then the test class, then superclasses from the nearest up, and then, for a [annotationname]`@Nested` test, enclosing classes from the innermost out. | ||
|
|
||
| [source,java] | ||
| ---- | ||
| @BrowserlessTestConfig(applicationProperties = "base.property=fromBase") | ||
| abstract class AbstractViewTest extends BrowserlessTest { | ||
| } | ||
|
|
||
| @BrowserlessTestConfig(featureFlags = "myExperimentalFeature") | ||
| class CartViewTest extends AbstractViewTest { | ||
| // Both base.property and myExperimentalFeature apply | ||
| } | ||
| ---- | ||
|
|
||
| Lookup services are the exception: they accumulate instead of replacing each other, so a test method can add a service, but cannot remove one that its test class declares. The services that the Spring and Quarkus integrations need are always registered, and the test configuration never affects them. | ||
|
|
||
| A method-level annotation needs an environment built for each test method. When one environment is shared by the whole class, as with [classname]`BrowserlessClassExtension`, the annotation is rejected with an error naming the methods that carry it. Move it to the test class in that case. | ||
|
|
||
|
|
||
| == Configuring Without Annotations | ||
|
Check warning on line 78 in articles/flow/testing/browserless/test-configuration.adoc
|
||
|
|
||
| The same settings can be built in code. On a JUnit 6 extension: | ||
|
|
||
| [source,java] | ||
| ---- | ||
| @RegisterExtension | ||
| BrowserlessExtension extension = new BrowserlessExtension() | ||
| .withApplicationProperty("devmode.sessionSerialization.enabled", "true") | ||
| .withFeatureFlags("myExperimentalFeature"); | ||
| ---- | ||
|
|
||
| On the application context builder of a multi-user test: | ||
|
|
||
| [source,java] | ||
| ---- | ||
| try (var app = BrowserlessApplicationContext.create(builder -> builder | ||
| .withViewPackages(CartView.class) | ||
| .withFeatureFlags("myExperimentalFeature"))) { | ||
| // ... | ||
| } | ||
| ---- | ||
|
|
||
| Or by overriding [methodname]`testConfiguration()` on a test that extends a base class: | ||
|
|
||
| [source,java] | ||
| ---- | ||
| @Override | ||
| protected BrowserlessConfiguration testConfiguration() { | ||
| return BrowserlessConfiguration.builder() | ||
| .withConfiguration(super.testConfiguration()) | ||
| .withFeatureFlags("myExperimentalFeature") | ||
| .build(); | ||
| } | ||
| ---- | ||
|
|
||
| A configuration built on an extension or on the application context builder wins over the class-level annotation, and loses against the method-level one. A [methodname]`testConfiguration()` override ranks differently: [methodname]`super.testConfiguration()` returns the configuration already resolved from the annotations, so whatever the override adds on top of it wins over all of them, the method-level annotation included. Build on [methodname]`super.testConfiguration()` to refine the declared configuration, and leave out the values that a test method needs to override. | ||
|
|
||
| .Spring Properties Win | ||
| [NOTE] | ||
| With Spring, a Vaadin property defined in the Spring environment, such as `vaadin.devmode.sessionSerialization.enabled` in [filename]`application.properties`, is applied by [classname]`SpringServlet` on top of the test configuration, and therefore wins over [annotationname]`@BrowserlessTestConfig`. Use [annotationname]`@TestPropertySource` to override such a property for a test. Properties that are not Vaadin init parameters are unaffected. | ||
|
|
||
|
|
||
| [discussion-id]`CD70CAA5-6506-4810-BED5-0F54DCE2F0FA` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is true only for the JUnit extension.
BrowserlessApplicationContextonly uses the configuration built with its own builder; it does take into account any annotation.However, the annotation configuration can be provided explicitly by using
BrowserlessConfiguration.from(...)factory method.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, thanks — fixed. The precedence sentence now scopes the "wins over the class-level annotation" rule to the JUnit extensions, and the section says explicitly that a
BrowserlessApplicationContextnever looks at@BrowserlessTestConfig, with yourBrowserlessConfiguration.from(getClass())snippet as the way to opt in. Also noted thatfrom(...)resolves a single annotation rather than merging the hierarchy the way an extension does. The builder table on the multi-user page got the same correction.