Replies: 2 comments 6 replies
|
The |
|
The maintainer answer from @mkouba is correct — Here are the practical options: Option 1: Use @QuarkusComponentTest
class MyServiceTest {
@Inject
MyService service;
@Test
void testReturnsExpectedResult() {
var asserter = new io.quarkus.test.vertx.DefaultUniAsserter();
asserter.assertThat(
() -> service.findById(1L),
dto -> Assertions.assertThat(dto.name()).isEqualTo("expected")
);
asserter.execute();
}
}
Option 2: Block directly with Since @Test
void testMyService() {
MyDto result = service.findById(1L)
.await().indefinitely();
assertThat(result.name()).isEqualTo("expected");
}This is the most readable approach and perfectly fine in the Option 3: Switch to If your service uses Hibernate Reactive, Panache reactive, or anything that needs the actual Vert.x event loop, Bottom line: for pure CDI/logic unit tests, Option 2 ( |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
I would like to unit test some service methods that I use on endpoints that returns uni.
I was able to setup an QuarkusComponentTest based test that is mocking the repositories and some other required components and injecting the service well.
To assert uni result I know that I can use
UniAsserteras I do with tests using@QuarkusTest. But I don't know if I need to do anything more to use it while using@QuarkusComponentTest.What am I missing ?
All reactions