Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Best way to exclude AspectJ codes for unit tests.

Hi Andy,
Thank you for the response. I’ve read somewhere (cannot remember where and when) that ‘cflow’ might have performance problems. Is that true? I myself was thinking of ‘if(…)’ in combination with "@Test” (If callee has that annotation skip the Aspect code.)

I’m doing the compile time weaving so the LTW cannot be the case for me. 
What I do with my aspects is user authorization and a kind of logging which is not important in my tests for me and is not “part of my business logic" (I will test the aspect code and user authorization in other unit tests.) Additionally I want to test my code off-container for which I don’t have access to the user authentication and authorization server…..

What you suggested about the system property is a good idea (I assume you mean something like -DAspectJEn=true in jvm options and looking for that value at the beginning of my aspect code) but don’t you think that your argument about mixing the test conditions with 'production’ also applies here in this solution? (Although this gives me the flexibility of disabling the user authorization and those loggings in runtime if it is needed one day.)

Cheers.


On Apr 22, 2014, at 2:32 AM, Andy Clement <andrew.clement@xxxxxxxxx> wrote:

Well you can engineer the pointcut potentially using something like a 'cflow' component that makes the advice running conditional on the control flow it finds itself in. But then you would be introducing code that detects whether you are in a test into your woven code, which presumably is what you are going to put into 'production' - and you probably don't want that (do you?)

If you are load time weaving you could just run the tests without the LTW agent in the mix.

Why does the advice need to be removed? That may point to the right way to do it. I mean you could just do a system property check in your advice before the body of it executes and then pass in a system property when running tests...

I believe people have done the maven solution you are thinking of (not including the aspects when building for a particular test run) but I don't speak enough maven to advise on how to do that.


cheers,
Andy





On 18 April 2014 11:30, Sina <my.linked.account@xxxxxxxxxxxxxx> wrote:
Hi there,

I want to exclude aspectj codes from being executed when I unit test. What is the best way to do that? 

Manipulating my pointcut such that it does not execute when the caller has “@Test” annotation?
Using maven goals and exclusion tags? (If so how exactly?)
One note about the possible maven solution: I guess that maven solution will only help if "mvn test”  command is run and cannot help when running the unit test directly (Right clicking on the test file-> Run As JUnit Test) 

Thanks for the help in advance.


_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users


_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users


Back to the top