英文:
Why does the BeforeAllCallback not have a ParameterResolvers?
问题
以下是翻译好的内容:
在我的测试类中,我可以使用 @BeforeAll
注解一个设置方法,例如:
@BeforeAll
public void setUp(WebApplicationContext webApplicationContext, RestDocumentationContextProvider restDocumentation) {
this.mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext)
.apply(documentationConfiguration(restDocumentation)).build();
}
我想在一个实现了 BeforeAllCallback
接口的扩展中做同样的事情,例如:
public class MyExtension implements BeforeAllCallback {
@Override
public void beforeAll(ExtensionContext context) throws Exception {
// 与上述代码相同,但是我不能在签名中有 RestDocumentationContextProvider 或 WebApplicationContext
}
}
在扩展的 beforeAll
方法中不支持 ParameterResolvers
,这意味着我不能使用签名 ExtensionContext context, RestDocumentationContextProvider restDocumentation
。
注解和回调方法之间有什么区别?如何在我的扩展的 beforeAll
方法中获取 RestDocumentationContextProvider
的实例?
英文:
In my test class I can use @BeforeAll
to annotate a setup method e.g.
@BeforeAll
public void setUp(WebApplicationContext webApplicationContext, RestDocumentationContextProvider restDocumentation) {
this.mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext)
.apply(documentationConfiguration(restDocumentation)).build();
}
I want to do the same thing in an extension with the BeforeAllCallback
e.g.
public class MyExtension implements BeforeAllCallback {
@Override
public void beforeAll(ExtensionContext context) throws Exception {
// same as above, but I can not have RestDocumentationContextProvider in the signature or WebApplicationContext
}
}
In the extension beforeAll
there is no support for ParameterResolvers
which means I can not use the signature ExtensionContext context, RestDocumentationContextProvider restDocumentation
.
What is the difference between the annotation and the callback method? How can I get an instance of RestDocumentationContextProvider
in my extensions beforeAll method?
专注分享java语言的经验与见解,让所有开发者获益!
评论