public class QuarkusMock extends Object
javax.enterprise.context.ApplicationScoped
and
javax.enterprise.context.RequestScoped
.
To use this inject the bean into a test, and then invoke the mock
method with your mock.
Mocks installed in BeforeAll
will be present for every test,
while mocks installed within a test are cleared after the test has run. Note that you will
likely need to use TestInstance.Lifecycle#PER_CLASS
to have a non-static before all method
that can access injected beans.
Note that as the bean is replaced globally you cannot use parallel test execution, as this will
result in race conditions where mocks from one test are active in another.Constructor and Description |
---|
QuarkusMock() |
Modifier and Type | Method and Description |
---|---|
static <T> void |
installMockForInstance(T mock,
T instance)
Installs a mock for a CDI normal scoped bean
|
static <T> void |
installMockForType(T mock,
Class<? super T> instance,
Annotation... qualifiers)
Installs a mock for a CDI normal scoped bean
|
public static <T> void installMockForInstance(T mock, T instance)
T
- The bean typemock
- The mock objectinstance
- The CDI normal scoped bean that was injected into your testpublic static <T> void installMockForType(T mock, Class<? super T> instance, Annotation... qualifiers)
T
- The bean typemock
- The mock objectinstance
- The type of the CDI normal scoped bean to replacequalifiers
- The CDI qualifiers of the bean to mockCopyright © 2021 JBoss by Red Hat. All rights reserved.