You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/main/asciidoc/getting-started-testing.adoc
+11-8Lines changed: 11 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1601,7 +1601,7 @@ import org.mockito.Mockito;
1601
1601
public class FooTest {
1602
1602
1603
1603
@RegisterExtension <1>
1604
-
static final QuarkusComponentTestExtension extension = new QuarkusComponentTestExtension().configProperty("bar","true");
1604
+
static final QuarkusComponentTestExtension extension = QuarkusComponentTestExtension.builder().configProperty("bar","true").build();
1605
1605
1606
1606
@Inject
1607
1607
Foo foo;
@@ -1621,9 +1621,10 @@ public class FooTest {
1621
1621
=== Lifecycle
1622
1622
1623
1623
So what exactly does the `QuarkusComponentTest` do?
1624
-
It starts the CDI container and registers a dedicated xref:config-reference.adoc[configuration object] during the `before all` test phase.
1625
-
The container is stopped and the config is released during the `after all` test phase.
1626
-
The fields annotated with `@Inject` and `@InjectMock` are injected after a test instance is created and unset before a test instance is destroyed.
1624
+
It starts the CDI container and registers a dedicated xref:config-reference.adoc[configuration object].
1625
+
If the test instance lifecycle is `Lifecycle#PER_METHOD` (default) then the container is started during the `before each` test phase and stopped during the `after each` test phase.
1626
+
However, if the test instance lifecycle is `Lifecycle#PER_CLASS` then the container is started during the `before all` test phase and stopped during the `after all` test phase.
1627
+
The fields annotated with `@Inject` and `@InjectMock` are injected after a test instance is created.
1627
1628
Finally, the CDI request context is activated and terminated per each test method.
1628
1629
1629
1630
=== Auto Mocking Unsatisfied Dependencies
@@ -1637,13 +1638,15 @@ You can inject the mock in your test and leverage the Mockito API to configure t
1637
1638
=== Custom Mocks For Unsatisfied Dependencies
1638
1639
1639
1640
Sometimes you need the full control over the bean attributes and maybe even configure the default mock behavior.
1640
-
You can use the mock configurator API via the `QuarkusComponentTestExtension#mock()` method.
1641
+
You can use the mock configurator API via the `QuarkusComponentTestExtensionBuilder#mock()` method.
1641
1642
1642
1643
=== Configuration
1643
1644
1644
-
A dedicated `SmallRyeConfig` is registered during the `before all` test phase.
1645
-
Moreover, it's possible to set the configuration properties via the `QuarkusComponentTestExtension#configProperty(String, String)` method or the `@TestConfigProperty` annotation.
1646
-
If you only need to use the default values for missing config properties, then the `QuarkusComponentTestExtension#useDefaultConfigProperties()` or `@QuarkusComponentTest#useDefaultConfigProperties()` might come in useful.
1645
+
You can set the configuration properties for a test with the `@io.quarkus.test.component.TestConfigProperty` annotation or with the `QuarkusComponentTestExtensionBuilder#configProperty(String, String)` method.
1646
+
If you only need to use the default values for missing config properties, then the `@QuarkusComponentTest#useDefaultConfigProperties()` or `QuarkusComponentTestExtensionBuilder#useDefaultConfigProperties()` might come in useful.
1647
+
1648
+
It is also possible to set configuration properties for a test method with the `@io.quarkus.test.component.TestConfigProperty` annotation.
1649
+
However, if the test instance lifecycle is `Lifecycle#_PER_CLASS` this annotation can only be used on the test class and is ignored on test methods.
0 commit comments