You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Jason van Zyl <jv...@maven.org> on 2004/07/10 20:24:22 UTC

Re: Reactor: tests failing (working dir set to master proj dir not child proj dir)

On Sat, 2004-07-10 at 13:08, Omair-Inam Abdul-Matin wrote:
> I've tried the following and my unit tests still fail because the 
> working directory seems to be the directory of the master project.

There is no way to reliably set the working directory in Java. To make
your tests reactor-able you must reference resources using the "basedir"
system property that is made available in tests by the junit plugin.

So the general pattern is:

public class MyTest extends TestCase
{
  private String basedir;

  protected void setUp()
  {
      basedir = System.getProperty( "basedir" );
  }

  public void testThatUsesAResourceFromTheFileSystem()
  {
      File resource = new File( basedir, "src/test/resources/MyTestResource.txt" );

      // do you stuff with the file system resource.
  }
}



-- 
jvz.

Jason van Zyl
jason@maven.org
http://maven.apache.org

happiness is like a butterfly: the more you chase it, the more it will
elude you, but if you turn your attention to other things, it will come
and sit softly on your shoulder ...

 -- Thoreau 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Re: Reactor: tests failing (working dir set to master proj dir not child proj dir)

Posted by Brett Porter <br...@gmail.com>.
this isn't a generic method for getting maven properties, but basedir is special

On Sat, 10 Jul 2004 18:43:25 -0400, Omair-Inam Abdul-Matin
<oi...@cs.uwaterloo.ca> wrote:
> Jason van Zyl wrote:
> > On Sat, 2004-07-10 at 13:08, Omair-Inam Abdul-Matin wrote:
> >
> >>I've tried the following and my unit tests still fail because the
> >>working directory seems to be the directory of the master project.
> >
> >
> > There is no way to reliably set the working directory in Java. To make
> > your tests reactor-able you must reference resources using the "basedir"
> > system property that is made available in tests by the junit plugin.
> >
> > So the general pattern is:
> >
> > public class MyTest extends TestCase
> > {
> >   private String basedir;
> >
> >   protected void setUp()
> >   {
> >       basedir = System.getProperty( "basedir" );
> >   }
> >
> >   public void testThatUsesAResourceFromTheFileSystem()
> >   {
> >       File resource = new File( basedir, "src/test/resources/MyTestResource.txt" );
> >
> >       // do you stuff with the file system resource.
> >   }
> > }
> >
> >
> > 
> Thanks... that's exactly what I was looking for..  I didn't know how to
> fetch maven-defined properties in a java file.
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Reactor: tests failing (working dir set to master proj dir not child proj dir)

Posted by Omair-Inam Abdul-Matin <oi...@cs.uwaterloo.ca>.
Jason van Zyl wrote:
> On Sat, 2004-07-10 at 13:08, Omair-Inam Abdul-Matin wrote:
> 
>>I've tried the following and my unit tests still fail because the 
>>working directory seems to be the directory of the master project.
> 
> 
> There is no way to reliably set the working directory in Java. To make
> your tests reactor-able you must reference resources using the "basedir"
> system property that is made available in tests by the junit plugin.
> 
> So the general pattern is:
> 
> public class MyTest extends TestCase
> {
>   private String basedir;
> 
>   protected void setUp()
>   {
>       basedir = System.getProperty( "basedir" );
>   }
> 
>   public void testThatUsesAResourceFromTheFileSystem()
>   {
>       File resource = new File( basedir, "src/test/resources/MyTestResource.txt" );
> 
>       // do you stuff with the file system resource.
>   }
> }
> 
> 
> 
Thanks... that's exactly what I was looking for..  I didn't know how to 
fetch maven-defined properties in a java file.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org