Loading ...
Sorry, an error occurred while loading the content.

Re: On extending JUnit with AspectJ...

Expand Messages
  • kumar@bigfoot.com
    Dear All, Firstly i was happy to see david s detailed mail on this problem, i hv been facing a similar issue, and was wondering how to go about it, i hv
    Message 1 of 3 , May 1, 2001
    • 0 Attachment
      Dear All,

      Firstly i was happy to see david's detailed mail on this problem,

      i hv been facing a similar issue, and was wondering how to go about
      it, i hv started using junitee ,or the servlet that comes along with
      that... my server side unit tests are deployed as part of the server

      I would love to be able to test it from client classes?
      Is it possible to make my test programs run in the same server vm??
      but not be part of the weblogic server process??? Most of the tests
      are server side ejb- test programs.

      I am on weblogic 5 everytime i change my unit tests i hv to restart
      weblogic, weblogic 6 is supposed to have a dynamic classloader, that
      reloads ordinary java classes, but is there a simpler solution, than
      migrating??.. and getting all the travails of weblogic 6.

      how does one de-couple the unit tests from the server & make them
      separate, and easily changeable..

      I was wondering if you have found a solution / work around for the

      Hope to hear from you folks,

      Many thanks Once again,

      Krishna Kumar

      --- In junit@y..., David Li <david@d...> wrote:
      > Hi,
      > I think I just found a solution to my long time problem with
      JUnit. We
      > do development mostly on server side components and most of these
      > side classes need to run with the server context properly setup.
      > Setting up these server contxt often involve using specialized
      > classloader to load the class. Using JUnit's native test runner
      > conflict with these classloader. ;(
      > We end up have to write our implementation of TestRunner for each
      > these environment and we often have to implement all three
      > The work is tedious and this makes tracking new version of JUnit a
      > harder. :(
      > There doesn't seem to be a good Object Oriented Java based
      solution to
      > this problem. The problem of having to adapt each TestRunner to
      > environment will requires extending all three TestRunner at the same
      > time and have to call the class different names.
      > Aspect Oriented Programming (www.aspectj.org) seem to solve this
      > problem elegantly. The following is a quick sample codes on adapting
      > Log4J into JUnit which extending all three TestRunner in one file.
      > The problem: We use Log4J in our components and JUnit to unit
      test of
      > the components. The problem is that Log4J need to be initialized at
      > least once from the main method. Doing it in a OO way will require
      us to
      > extending all three TestRunner to something like
      > public class TestRunnerWithLog4J extends junit.awtui.TestRunner
      > {
      > public static void main(String[] args) {
      > Log4J_INIT_CODES_HERE;
      > super.main(args);
      > }
      > }
      > Second problem we are having is that we need to document the fact
      > make our developers aware what TestRunner to be use with what
      > We now have three versions of TestRunner:
      > TestRunnerWithEnhydra, TestRunnerWithOzone and TestRunnerWithLog4.
      > In this case, Ozone uses Log4J as well. The list grows very fast
      and the
      > extensions codes become a big tangled codes and maintaince hell!
      > AspectJ seems to provide a very elegant solution to this. The
      > is my first try to use AspectJ to solve this problem:
      > ---
      > package junit.aspect;
      > aspect Log4JRunner {
      > pointcut runnerMain():
      > executions(public static void
      > junit.awtui.TestRunner.main(String[])) ||
      > executions(public static void
      > junit.textui.TestRunner.main(String[])) ||
      > executions(public static void
      > junit.swingui.TestRunner.main(String[]));
      > before(): runnerMain() {
      > org.apache.log4j.BasicConfigurator.configure();
      > org.apache.log4j.Category.getRoot().setPriority
      > }
      > }
      > ---
      > This aspect simply extending the main method in each TestRunner to
      > properly initialize the Log4J. This extension gives three main
      > advantages:
      > 1. No modification to the original JUnit codes
      > 2. No messy subclass of TestRunner to maintaine.
      > 3. No special documents for each TestRunner for each environment.
      > I'd like to get the opinion of the JUnit users and developers on
      > AOP as the extension proramming for JUnit.
      > Thanks.
      > David Li
      > DigitalSesame
    • kumar@bigfoot.com
      Hi all, My earlier mail didn t get thru i am not too surewhy!! Problem: I have serverside junit code that i test using a test servlet on my
      Message 2 of 3 , May 1, 2001
      • 0 Attachment
        Hi all,
        My earlier mail didn't get thru i am not too surewhy!!

        I have serverside junit code<<for ejbs>> that i test using a test
        servlet on my weblogic 5 server. the problem is everytime i change my
        test java code, i need to bring up and down the weblogic server. This
        is supposedly fixed with the dynamic classloader in weblogic 6, but
        is there a easier way around this problem, how can i get my junit-
        test code to run on the same vm without making the classes a part of
        the server procesS? So that i can de-couple the test code from the

        Many thanks to everyone,

        krishna kumar
      Your message has been successfully submitted and would be delivered to recipients shortly.