Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] testing advices

Hi -

Generally for testing whether advice ran we emit a message 
for each advice (and other points of interest), and then check the 
sequence of messages to see if they are correct.  With some 
library support, you can set up the test, capture the signals,
manually inspect for correctness, and then set that series as
the correct one when verifying.  Just remember what's guaranteed
by way of order (e.g., before advice, precedent advice) and
what's not guaranteed (e.g., advice in unrelated aspects) so 
you don't assume an arbitrary order will always be produced
(since another correct compiler can produce another correct order 
when not guaranteed).

Because we're usually testing for bugs, we typically have
the advice itself emit the message.  But another way is to
use an aspect to emit the messages - something like

aspect SignalAdvice {
  before() : adviceexecution() && !cflow(within(SignalAdvice)) {
    // emit message with target info
  }
}

But getting good information about the advice being executed or
the join point it is matching can be hard.

Nor does this solve the question of testing whether the advice
code works as expected; for that I use delegation to testable
methods when possible, and write custom tests otherwise.
Anything else involves a lot of hoops to directly invoke the
advice which, by design, are not named/referenceable.  There 
are many proposals out there for resolving this (e.g., with
annotations and aspect reflection), but none in widespread
use AFAICT.  Perhaps aUnit will save the day!

hth - Wes

> ------------Original Message------------
> From: Valerio Schiavoni <ervalerio@xxxxxxxxxx>
> To: aspectj-users@xxxxxxxxxxx
> Date: Mon, Aug-22-2005 0:42 AM
> Subject: [aspectj-users] testing advices
>
> Hello. consider a test case containing for example this test:
> 
> public void test1AnnotationOnRoot()
>         throws Exception {
>             ...   
>           
>                    //INVOKE A SERVICE
>                    ((Main)root.getFcInterface("root_main")).main(null);
> }
> 
> how could I test if a given advice has been correctly executed ?
> 
> something like:
> 
> assertPointcutMatched(MyAspect.aj, pcd_name);
> assertAdviceExecuted(MyAspect.aj, advice_name);
> 
> could be usefull. but more in general, i want to test that my pointcuts 
> 
> and my advices match and execute at the right moment.
> 
> is there ant support for this ?
> 
> the aunit project doesn't look very active at the moment (or maybe it 
> is, but no releases yet).
> 
> valerio
> 
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
> 



Back to the top