0

我的 AOP 是@AfterReturing,切入点是注解。这是一个简单的例子。

@interface CustomLog {
  String message
}

@Aspect
@Configuration
@EnableAspectJAutoProxy
class AopConfig {
  
  @AfterReturning(value = "@annotation(~~~~CustomLog)"
  public void doSomething() {...}
}

@EanbleSecurity
class SecurityConfig {
  ...
  protected void configure(HttpSecurity http) {
    formLogin().successHandler(loginSuccessHandler)
  }
}

class LoginSuccessHandler extends SimpleUrlAuthenticationSuccessHandler {
  @CustomLog
  public void onAuthenticationSucess(....) {
     ...
  }
}

如果登录过程成功,我想对 AOP 进行单元测试doSomething()

我如何在没有@SpringBootTest, 使用的情况下进行测试@WebMvcTest

我已经测试过这种方式

@WebMvcTest(
  includeFilters = {
    @ComponentScan.Filter(
      classes = {
        EnableWebSecurity.class
        , EnableAspectJAutoProxy.class
      }
    )
  }
)

但这样我就不得不对每个控制器的模拟 bean、拦截器和相关 bean。我怎样才能用just测试登录过程LoginSucessHandler

4

0 回答 0