【问题标题】:AspectJ pointcut to match methods annotated with @TestAspectJ 切入点以匹配使用 @Test 注释的方法
【发布时间】:2018-05-08 02:00:53
【问题描述】:

我正在构建一个模块,用于侦听 TestNG 测试并在测试方法开始执行之前执行某些操作,用于每个测试方法。 我只想知道测试(方法)何时开始执行、方法名称和可选的测试类名称。

我成功地为 testNG 的调用者调用编写切入点。它奏效了。

@Pointcut("execution(* org.testng.internal.IInvoker.invokeTestMethods(..))")

相反,我想知道,由于每个测试方法都用 @org.testng.annotations.Test 注释,我如何编写切入点来捕获每个用 @org.testng.annotations.Test 注释的测试方法的执行 joinPoint?

这是我的测试的样子

@BeforeClass
    public void setup() {
       //setup logic
    }
    @BeforeMethod
    private void configure() {
        //config logic
    }

    @Test
    public void testLoad() {
    //test
    }

    @Test
    public void testForm() {
    //test
    }   

我尝试了一些切入点,结果证明它们是无效的。 注意:我正在使用加载时间编织。

【问题讨论】:

    标签: java testng aop aspectj spring-aop


    【解决方案1】:

    试试这个

    "execution(* *(..)) && @annotation(org.testng.annotations.Test)"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-02-12
      • 1970-01-01
      • 1970-01-01
      • 2011-02-15
      • 2013-02-12
      • 1970-01-01
      相关资源
      最近更新 更多