为什么 `BeforeAllCallback` 没有 `ParameterResolvers`?

huangapple 未分类评论40阅读模式
英文:

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?

huangapple
  • 本文由 发表于 2020年7月24日 19:39:26
  • 转载请务必保留本文链接:https://java.coder-hub.com/63072801.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定