junit5扩展中的Quarkustest访问豆
我有@quarkustest
基于测试类。我想实现与我的quarkus测试上下文的特定豆类交互的Junit 5扩展名(eachCallback,aftereachCallback)。我尝试了cdi.current()
,但结果为:java.lang.illegalstateexception:无法
在春季基于春季的测试中找到CDIPROVIDE ,例如,我访问IpplicationContext
@Override
public void beforeEach(final ExtensionContext extensionContext) {
final ApplicationContext applicationContext = SpringExtension.getApplicationContext(extensionContext);
MyBean myBean = applicationContext.getBean(MyBean.class);
}
,然后可以从我的测试上下文中使用编程性查询混凝土豆。有什么类似的夸克测试方法吗?我的意思是,我可以@inject
将bean进入我的测试类,并以@beforeach
方法访问它,但是我正在寻找一种更“可重复使用的”解决方案。
非常感谢。
I have @QuarkusTest
based test class. And I want to implement a JUnit 5 extension (BeforeEachCallback, AfterEachCallback) that interacts with a specific bean of my Quarkus test context. I tried CDI.current()
, but that results into: java.lang.IllegalStateException: Unable to locate CDIProvide
In Spring based test for example I access the ApplicationContext via
@Override
public void beforeEach(final ExtensionContext extensionContext) {
final ApplicationContext applicationContext = SpringExtension.getApplicationContext(extensionContext);
MyBean myBean = applicationContext.getBean(MyBean.class);
}
which I can then use to programmatically query concrete beans from my test context. Is there any kind of similar approach to Quarkus tests? I mean, I can @Inject
the bean into my test class and access it in a @BeforeEach
method, but I am looking for a more 'reusable' solution.
Thank you very much.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
geoand 让我走上正确的轨道。一种有效的方法是使用 quarkusteStepeStepEfferrer“
因此,鉴于我的自定义QuarkusteStbeforeachCallback实现了现在,该实现现在支持通过CDI访问Quarkus bean:
和服务声明文件
src/test/test/resources/Meta-inf/services/io.quarkus.junit.junit.callback.quarkustestepestepefte.quarkustestebock.quarkusteceachcalforeachcallbackcallback
使用内容
com.something.test.mybeforeachcallback
我现在可以在我的
@quarkustest
测试中使用它,例如:这比我们用Spring所用的要复杂一些引导测试,但肯定有效。
geoand put me on the right track. A valid approach would be to use QuarkusTestBeforeEachCallback / QuarkusTestMethodContext.
So given my custom QuarkusTestBeforeEachCallback implementation which now supports accessing quarkus beans via CDI:
and a service declaration file
src/test/resources/META-INF/services/io.quarkus.test.junit.callback.QuarkusTestBeforeEachCallback
with the content
com.something.test.MyBeforeEachCallback
I now can use it in my
@QuarkusTest
tests e.g:This is a bit more complicated than what we are used to with Spring Boot tests, but it definitely works.