Hi there!

I got another problem in trying to create tests for my application with junit
and ant; this one is kinda weird, I think.
The application is a database-based server that has to be started in order to
be tested properly. So I have two targets that are executed one after the
other. The first uses a java-task to start the server in ant's VM
(fork="false"). The second is the junit-task (also fork="false") that tests
some server output.

The "first" class of the server ("Supervisor") now has a public static field
describing it's sole instance, so I have a starting point from which to wander
off into the server. But when I try to access this field from my test class the
class Supervisor is initialized a second time and the fields value is (of
course) (reset to) null; I can't find the server. I tried direct access to the
static fild (Supervisor.lastInstance) and introspection - no difference.

I'm quite positive that ant doesn't start a second VM for either the server or
junit. Does anyone have an idea why I cannot access my loaded and initialized
server class from the test class?

Here are some excerpts from the build.xml, the server class, the test class and
ant's output.
(Note: TestBGStarter just wraps the Supervisor)
---------------------------------------------------
  <target name="test-start-server" depends="compile">
    <echo message="starting server"/>
    <delete file="test.server.log"/>
    <java classname="xxx.supervisor.TestBGStarter"
          
classpath="${oracle.home}/jdbc/lib/classes111.zip:${build.classpath}:${compile.dir}"
          fork="false"
          failonerror="true">
      <arg line="-config test.server.config"/>
    </java>
    <echo message="waiting for server to come up"/>
    <exec executable="isserverup.pl">
      <arg line="test.server.log"/>
    </exec>
    <echo message="server running"/>
  </target>

  <target name="test-do" depends="compile">
    <junit printsummary="true"
           fork="false">
      <classpath>
        <pathelement location="${oracle.home}/jdbc/lib/classes111.zip"/>
        <pathelement path="${build.classpath}"/>
        <pathelement location="${compile.dir}"/>
      </classpath>
      <formatter type="plain"
                 usefile="false"/>
      <test name="xxx.command_post.ASInfoTester"
            fork="false"/>
    </junit>
  </target>
---------------------------------------------------
  private Supervisor( ConfigFile conf )
  {
    config = conf;
    System.err.print( "Supervisor::init: lastInstance from "+lastInstance );
    lastInstance = this;
    System.err.println( " to "+lastInstance );
  }

  public static Supervisor lastInstance;

static { System.err.println( "INIT OF CLASS Supervisor" ); }
---------------------------------------------------
  public void setUp()
  {
    Class sup_class;
    Field sup_self_field;
    Supervision server;
    CommandsSupervisor cs;

    // get ref to server Supervisor
    try
    {
//       sup_class = Class.forName( "xxx.supervisor.Supervisor", false, 
this.getClass().getClassLoader() );
//       sup_self_field = sup_class.getField( "lastInstance" );
// System.err.println("found field: "+sup_self_field.getName()+" mod: 
"+sup_self_field.getModifiers()+" class: 
"+sup_self_field.getDeclaringClass().getName()+" type: 
"+sup_self_field.getType().getName()+" acc: "+sup_self_field.isAccessible() );
//       server = (Supervision)sup_self_field.get( null );  // static field;
System.err.println("looking for Supervisor");
      server = Supervisor.lastInstance;
System.err.println("found supervisor: "+server);
    }
    catch( Exception e ) { e.printStackTrace(); }
  }
---------------------------------------------------
Ant version 1.3 compiled on March 2 2001

Buildfile: build.xml
Detected Java Version: 1.3
Detected OS: Linux

[...]

test-start-server:
     [echo] starting server
   [delete] Deleting: /xxx/test.server.log
     [java] Running in same VM xxx.supervisor.TestBGStarter -config test.server.config
INIT OF CLASS Supervisor
     [echo] waiting for server to come up
     [exec] Myos = Linux
     [exec] isserverup.pl test.server.log
Supervisor::init: lastInstance from null to xxx.supervisor.Supervisor@f73c1
     [echo] server running

test-do:
    [junit] Using System properties {}
    [junit] Using CLASSPATH [...]
    [junit] Running xxx.command_post.ASInfoTester
looking for Supervisor
INIT OF CLASS Supervisor
found supervisor: null
---------------------------------------------------

greetinx, Kai
-- 
"Leave it to the businessmen .... to die young."                   <Fisher-Z>
[EMAIL PROTECTED]                  +                 www.picturesafe.de
picturesafe GmbH, Lueerstr. 3, D-30175 Hannover          fon:+49 511 85620 56
++ PGP Key fingerprint =  D2 B9 58 DC 36 52 DB 6C  18 CC 43 9F 68 E0 21 97 ++

Reply via email to