4

您好,我在将 AspectJ 与 Junit 测试集成时遇到了麻烦。

我需要为测试套件中的每个测试获取不同的日志。所以我需要知道什么时候运行一个新的测试用例,什么时候完成。我如何定义这样的切入点?

以下切入点对我不起作用,它只输入一次。

pointcut testIsAboutToBegin()
: execution (* *.test(..));
4

2 回答 2

0

您好,您应该为此使用 before() 和 after(),试试这个:

before () : testIsAboutToBegin() {
    System.out.println("starting test ... ");
}

after () : testIsAboutToBegin() {
    System.out.println("ending test ... ");
}


//for GetJUnit 4.x
pointcut testJUnit4xIsAboutToBegin() : execution(@Test * *(..))

pointcut testIsAboutToBegin() : execution (* *.test*(..));
于 2014-07-14T14:24:38.997 回答
0

使用周围的建议怎么样?

pointcut aroundTest(): 
    execution(public void test*(..));

  void around() throws Exception: aroundTest() {
     LOG.info("start");
     proceed();
     LOG.info("stop");
  }
于 2013-06-11T12:27:54.860 回答