如何设置junit以与aspectJ一起运行

时间:2012-11-21 06:45:47

标签: junit aspectj

我想运行junit测试,同时希望在Eclipse中使用aspectJ将跟踪记录在文件中。

1 个答案:

答案 0 :(得分:0)

如果你有AspectJ in Action书(第2版),它将在第10章中介绍。

您需要在Eclipse中创建一个Aspect(.aj)文件,无论如何都要调用它(可能是TraceAspect)。

然后你需要定义(1)切入点:

pointcut trace() : execution (* *.*(..)) && (!within(TraceAspect))

然后定义一个方法,例如before()/ around()/ execution()/ call()

before() : trace() {
    Signature sign = thisJoinPointStaticPart.getSignature();
    // Do stuff
}

其他一些例子是:

http://code.google.com/p/springside/source/browse/springside3/trunk/examples/showcase/src/main/java/org/springside/examples/showcase/log/trace/TraceAspect.java?r=1105

http://code.google.com/p/dremel/source/browse/src/dremel/common/loggingaspect/TraceAspect.aj?repo=metaxa&r=bb10a0d0a9e82d3fe6bb2b39e0f3a44d7ceafc4b