You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Marco Tedone <mt...@jemos.org> on 2004/02/16 22:57:15 UTC

Unit testing question

Hi, I build my projects using maven. Maven executes automatically junit tests. I've got more than one test. Both of those tests use the services offered by a class, which I've implemented as a Singleton. The class is created after each test class has completed, thus my singleton is like as it doesn't exist.

Is there a solution to this problem?

Marco

Re: Unit testing question - typo

Posted by Marco Tedone <mt...@jemos.org>.
[snip]
> 2) The unit tests fail because the AbstractTest from which they inherit
can
> find a property file (and because of point 1 I don't know the reason)
>
[/snip]

Please read:

2) The unit tests failed because the AbstractTest from which they inherit
can't find a property file (and because of point 1 I don't know the reason)


Sorry for the typo.

Marco




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


Re: Unit testing question

Posted by Marco Tedone <mt...@jemos.org>.
I obviously already went for the first, but I was wondering what will it
happen when my application will grow significantly. On the other hand, I
tried the second one, with fork=true, and:

1) First of all I must admit that I don't know what the impact of this
change will be on the effective application (therefore I won't be able to
solve further bugs)
2) The unit tests fail because the AbstractTest from which they inherit can
find a property file (and because of point 1 I don't know the reason)

Marco
----- Original Message ----- 
From: "Sebastien Sahuc" <ss...@intalio.com>
To: "Maven Users List" <us...@maven.apache.org>
Sent: Tuesday, February 17, 2004 9:34 PM
Subject: Re: Unit testing question


> I'm not surprised to hear your singleton class is being instanciated
> more than once. This is due to the fact the maven create a separate
> classloader for each TestCase it finds and executes. There is two way
> to quickly solve your problem. First would be to aggregate all test
> cases that use the singleton service into a single test suite and have
> maven run only the test suite and rule out all independent test cases.
> The second solution is simply to fork the junit JVM with the property
> maven.junit.fork=true.
>
> Sebastien
>
> On Feb 17, 2004, at 1:16 PM, Marco Tedone wrote:
>
> > Please find in the attached picture the architecture of my unit
> > testings.
> > Basically, I created two unit test classes which extend and
> > AbstractTest
> > class which, in turn, extends the JUnit TestCase class.
> >
> > Both classes retrieve a logger from a class implemented as Singleton
> > (therefore only one instance should be created). I put a log message
> > in the
> > the constructor to see how many times the constructor gets invoked (and
> > actually it is invoked twice while it should be invoked only once as
> > this is
> > a singleton).
> >
> > Attached you will find the unit test classes, logger factory and a PDF
> > with
> > the dump of the unit test activity, showing the message logged from the
> > Singleton constructor. For simplicity, the diagram doesn't show the
> > package
> > hierarchy, which is available on request.
> >
> > If you really want to run the application, you may want to download it
> > and
> > the logging framework, following the instructions at the following
> > site:
> >
> > http://www.jemos.org
> >
> > Best Regards,
> >
> > Marco
> >
> > ----- Original Message -----
> > From: "Charles Daniels" <    >
> > To: "Maven-users" <us...@maven.apache.org>
> > Sent: Tuesday, February 17, 2004 7:21 AM
> > Subject: Re: Unit testing question
> >
> >
> >> This sounds more like a problem with the way you have implemented your
> > unit tests, not a problem
> >> with Maven.  Can you provide more details on how you have written your
> > test classes?
> >>
> >> --- Marco Tedone <mt...@jemos.org> wrote:
> >>> Hi, I build my projects using maven. Maven executes automatically
> >>> junit
> > tests. I've got more
> >>> than one test. Both of those tests use the services offered by a
> >>> class,
> > which I've implemented
> >>> as a Singleton. The class is created after each test class has
> > completed, thus my singleton is
> >>> like as it doesn't exist.
> >>>
> >>> Is there a solution to this problem?
> >>>
> >>> Marco
> >>
> >>
> >> ---------------------------------------------------------------------
> >> 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
>
>
> ---------------------------------------------------------------------
> 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: Unit testing question

Posted by Sebastien Sahuc <ss...@intalio.com>.
I'm not surprised to hear your singleton class is being instanciated 
more than once. This is due to the fact the maven create a separate 
classloader for each TestCase it finds and executes. There is two way 
to quickly solve your problem. First would be to aggregate all test 
cases that use the singleton service into a single test suite and have 
maven run only the test suite and rule out all independent test cases. 
The second solution is simply to fork the junit JVM with the property 
maven.junit.fork=true.

Sebastien

On Feb 17, 2004, at 1:16 PM, Marco Tedone wrote:

> Please find in the attached picture the architecture of my unit 
> testings.
> Basically, I created two unit test classes which extend and 
> AbstractTest
> class which, in turn, extends the JUnit TestCase class.
>
> Both classes retrieve a logger from a class implemented as Singleton
> (therefore only one instance should be created). I put a log message 
> in the
> the constructor to see how many times the constructor gets invoked (and
> actually it is invoked twice while it should be invoked only once as 
> this is
> a singleton).
>
> Attached you will find the unit test classes, logger factory and a PDF 
> with
> the dump of the unit test activity, showing the message logged from the
> Singleton constructor. For simplicity, the diagram doesn't show the 
> package
> hierarchy, which is available on request.
>
> If you really want to run the application, you may want to download it 
> and
> the logging framework, following the instructions at the following 
> site:
>
> http://www.jemos.org
>
> Best Regards,
>
> Marco
>
> ----- Original Message -----
> From: "Charles Daniels" <    >
> To: "Maven-users" <us...@maven.apache.org>
> Sent: Tuesday, February 17, 2004 7:21 AM
> Subject: Re: Unit testing question
>
>
>> This sounds more like a problem with the way you have implemented your
> unit tests, not a problem
>> with Maven.  Can you provide more details on how you have written your
> test classes?
>>
>> --- Marco Tedone <mt...@jemos.org> wrote:
>>> Hi, I build my projects using maven. Maven executes automatically 
>>> junit
> tests. I've got more
>>> than one test. Both of those tests use the services offered by a 
>>> class,
> which I've implemented
>>> as a Singleton. The class is created after each test class has
> completed, thus my singleton is
>>> like as it doesn't exist.
>>>
>>> Is there a solution to this problem?
>>>
>>> Marco
>>
>>
>> ---------------------------------------------------------------------
>> 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


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


Re: Unit testing question

Posted by Marco Tedone <mt...@jemos.org>.
Please find in the attached picture the architecture of my unit testings.
Basically, I created two unit test classes which extend and AbstractTest
class which, in turn, extends the JUnit TestCase class.

Both classes retrieve a logger from a class implemented as Singleton
(therefore only one instance should be created). I put a log message in the
the constructor to see how many times the constructor gets invoked (and
actually it is invoked twice while it should be invoked only once as this is
a singleton).

Attached you will find the unit test classes, logger factory and a PDF with
the dump of the unit test activity, showing the message logged from the
Singleton constructor. For simplicity, the diagram doesn't show the package
hierarchy, which is available on request.

If you really want to run the application, you may want to download it and
the logging framework, following the instructions at the following site:

http://www.jemos.org

Best Regards,

Marco

----- Original Message ----- 
From: "Charles Daniels" <    >
To: "Maven-users" <us...@maven.apache.org>
Sent: Tuesday, February 17, 2004 7:21 AM
Subject: Re: Unit testing question


> This sounds more like a problem with the way you have implemented your
unit tests, not a problem
> with Maven.  Can you provide more details on how you have written your
test classes?
>
> --- Marco Tedone <mt...@jemos.org> wrote:
> > Hi, I build my projects using maven. Maven executes automatically junit
tests. I've got more
> > than one test. Both of those tests use the services offered by a class,
which I've implemented
> > as a Singleton. The class is created after each test class has
completed, thus my singleton is
> > like as it doesn't exist.
> >
> > Is there a solution to this problem?
> >
> > Marco
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>


Re: Unit testing question

Posted by Charles Daniels <cj...@yahoo.com>.
This sounds more like a problem with the way you have implemented your unit tests, not a problem
with Maven.  Can you provide more details on how you have written your test classes?

--- Marco Tedone <mt...@jemos.org> wrote:
> Hi, I build my projects using maven. Maven executes automatically junit tests. I've got more
> than one test. Both of those tests use the services offered by a class, which I've implemented
> as a Singleton. The class is created after each test class has completed, thus my singleton is
> like as it doesn't exist.
> 
> Is there a solution to this problem?
> 
> Marco


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