AspectJ切入点匹配使用@Test注释的方法

时间:2017-11-24 05:16:35

标签: java testng aop aspectj spring-aop

我正在构建一个模块,用于监听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
    }   

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

1 个答案:

答案 0 :(得分:2)

试试这个

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