Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] How to?

Use the following aspect:

public aspect Analizer {
 pointcut testsFlow(TestCase testCase) :
     call(* MyClass.myMethod(..)) &&
cflow(execution (* junit.framework.TestCase+.test*()) && this(testCase)); before(TestCase testCase) : testsFlow(testCase) {
   System.out.println(testCase.getClass());
 }
}

And you have just used the wormhole design pattern!

-Ramnivas

===
Ramnivas Laddad,
Author, AspectJ in Action
http://ramnivas.com



André Dantas Rocha wrote:

Hi,
I'd like to print the TestCase name from witch myMethod is called (not directly, but in the TestCase control-flow). Is it possible via pointcut declaration? my code is shown below... public class MyClass {
  void xx() { myMethod(); }
  void myMethod() {...}
}
public void testM() {
  new MyClass().xx();
}
public aspect Analizer {
  pointcut testsFlow() :
      call(* MyClass.myMethod(..)) &&
      cflow(execution (* junit.framework.TestCase+.test*()));
before() : testsFlow() { System.out.println(thisJoinPoint); // not working, must print "testM"...
  }
}
Thanks, André



Back to the top