【问题标题】:How to setup junit to run with aspectJ如何设置junit以使用aspectJ运行
【发布时间】:2023-03-27 09:59:02
【问题描述】:

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

【问题讨论】:

    标签: junit aspectj


    【解决方案1】:

    如果您有 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

    【讨论】:

      猜你喜欢
      • 2011-01-12
      • 1970-01-01
      • 1970-01-01
      • 2021-12-26
      • 2012-08-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多