You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Alexander Sack <pi...@gmail.com> on 2007/05/23 21:25:35 UTC

JUnit4 test cases using @Before, @After fail test?

Hey folks, is this a known issue that if I use @Before it will fail my
test?  I searched some of the archives and saw some threads go by about
this.  Is this still an issue?

Thanks!

-aps

-- 
"What lies behind us and what lies in front of us is of little concern to
what lies within us." -Ralph Waldo Emerson

Re: JUnit4 test cases using @Before, @After fail test?

Posted by Alexander Sack <pi...@gmail.com>.
Bernd, thanks.  That did it, I switched to 4.3.1 and now it all works.
Weirdness.  AFAIK I thought Junit4 begin with @Before but I could be wrong
since 4.x is new to me (I just went to the FAQ and trieed out the test case
just to make sure surefire was working properly and chaos ensued).

Thanks again, I really appreciate it!

-aps

On 5/24/07, berndq <be...@gmx.net> wrote:
>
> Alexander Sack wrote:
> > Dennis, thanks for the tip.  Kinda obvious too...damn...
> >
> > Okay, so can someone tell me what I need to do to FORCE it to use
> > junit4?  I
> > specific junit-4.0 in my dependencies (scope is "test").  My parent dom
> of
> > the whole project has surefire plugin version set to 2.3.  I mean what
> else
> > do I have to do at this point?
>
> I have this in my parent pom and @Before works for me:
>
>    <dependencies>
>      <dependency>
>        <groupId>junit</groupId>
>        <artifactId>junit</artifactId>
>        <version>4.3.1</version>
>        <scope>test</scope>
>      </dependency>
>
> IIRC early versions of junit 4 did not call @Before on subclasses.
> So if by any chance your MyTest class is a subclass of e.g. TestCase
> and this was really a bug in junit 4.0 then this might be the cause.
>
> FWIW: I noticed yesterday taht the junit4 runner in eclipse 3.2.2 does
> not call @Before on subclases of TestCase.
>
> maybe mvn -X ... gives more information?
>
> best regards
> Bernd
>
> > -aps
> >
> > On 5/23/07, Dennis Cook <dj...@yahoo.com> wrote:
> >>
> >> It looks like junit 3.8 is still being used.  The reason the method
> name
> >> prefix with 'test' will be called by the older version.  The
> >> annotation is
> >> probably ignored.  Change the name of the test method to another
> >> prefix, and
> >> I bet it will not be executed.
> >>
> >> Alexander Sack <pi...@gmail.com> wrote: Btw, considering that @Test
> >> works, I'm pretty positive I'm using 2.3 at this
> >> point.  The only issue is the @Before seems to never get called.
> >>
> >> Anyone run into this before?
> >>
> >> -aps
> >>
> >> On 5/23/07, Alexander Sack
> >> wrote:
> >> >
> >> > Tom,
> >> >
> >> > Thanks sorry.  Yes I have specified in my root POM surefire-plugin
> >> 2.3but
> >> > not in my submodule one (I will try that right now).  The test ource
> is
> >> the
> >> > one straight out of the FAQ regarding the colleciton, very simple
> test,
> >> > passes on 3.8.1 but fails when I move up to 4.0 using the surefire
> >> > plugin.  I'm using Junit-4.0.
> >> >
> >> > Is suppose to work?  The surefire report claims there is a null
> >> pointer:
> >> >
> >> > Here is my source:
> >> >
> >> > import static org.junit.Assert.* ;
> >> >
> >> > import java.util.ArrayList;
> >> > import java.util.Collection;
> >> >
> >> > import org.junit.Before;
> >> > import org.junit.Test;
> >> >
> >> > public class MyTest  {
> >> >     private Collection c;
> >> >
> >> >     @Before
> >> >     public void setUp() {
> >> >         c = new ArrayList();
> >> >     }
> >> >
> >> >     @Test
> >> >     public void testSomeMethod() {
> >> >         assertTrue(c.isEmpty());
> >> >     }
> >> > }
> >> >
> >> > Claims c is null which it isn't provided @Before runs (if I eliminate
> >> the
> >> > method and put it in my testSomeMethod() it passes.  How can I tell
> >> what
> >> > version of surefire I'm running?  The -e just says that test case has
> >> > failed, etc stack.
> >> >
> >> > What am I doing wrong?  (man, I've used maven2 in all kinds of
> advanced
> >> > ways and I feel retarded that this is not working!).
> >> >
> >> > -aps
> >> >
> >> > On 5/23/07, Tom Huybrechts  wrote:
> >> > >
> >> > > would you mind sharing some more information ? POMs, exceptions,
> test
> >> > > source,  -X output ?
> >> > >
> >> > > As a general remark: make sure you have the latest surefire
> plugin...
> >> > >
> >> > > Tom
> >> > >
> >> > > On 5/23/07, Alexander Sack < pisymbol@gmail.com> wrote:
> >> > > > Hey folks, is this a known issue that if I use @Before it will
> fail
> >> my
> >> > > > test?  I searched some of the archives and saw some threads go by
> >> > > about
> >> > > > this.  Is this still an issue?
> >> > > >
> >> > > > Thanks!
> >> > > >
> >> > > > -aps
> >> > > >
> >> > > > --
> >> > > > "What lies behind us and what lies in front of us is of little
> >> concern
> >> > > to
> >> > > > what lies within us." -Ralph Waldo Emerson
> >> > > >
> >> > >
> >> > >
> ---------------------------------------------------------------------
> >> > > To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> >> > > For additional commands, e-mail: users-help@maven.apache.org
> >> > >
> >> > >
> >> >
> >> >
> >> > --
> >> > "What lies behind us and what lies in front of us is of little
> concern
> >> to
> >> > what lies within us." -Ralph Waldo Emerson
> >> >
> >>
> >>
> >>
> >> --
> >> "What lies behind us and what lies in front of us is of little concern
> to
> >> what lies within us." -Ralph Waldo Emerson
> >>
> >>
> >>
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>


-- 
"What lies behind us and what lies in front of us is of little concern to
what lies within us." -Ralph Waldo Emerson

Re: JUnit4 test cases using @Before, @After fail test?

Posted by berndq <be...@gmx.net>.
Alexander Sack wrote:
> Dennis, thanks for the tip.  Kinda obvious too...damn...
> 
> Okay, so can someone tell me what I need to do to FORCE it to use 
> junit4?  I
> specific junit-4.0 in my dependencies (scope is "test").  My parent dom of
> the whole project has surefire plugin version set to 2.3.  I mean what else
> do I have to do at this point?

I have this in my parent pom and @Before works for me:

   <dependencies>
     <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
       <version>4.3.1</version>
       <scope>test</scope>
     </dependency>

IIRC early versions of junit 4 did not call @Before on subclasses.
So if by any chance your MyTest class is a subclass of e.g. TestCase
and this was really a bug in junit 4.0 then this might be the cause.

FWIW: I noticed yesterday taht the junit4 runner in eclipse 3.2.2 does 
not call @Before on subclases of TestCase.

maybe mvn -X ... gives more information?

best regards
Bernd

> -aps
> 
> On 5/23/07, Dennis Cook <dj...@yahoo.com> wrote:
>>
>> It looks like junit 3.8 is still being used.  The reason the method name
>> prefix with 'test' will be called by the older version.  The 
>> annotation is
>> probably ignored.  Change the name of the test method to another 
>> prefix, and
>> I bet it will not be executed.
>>
>> Alexander Sack <pi...@gmail.com> wrote: Btw, considering that @Test
>> works, I'm pretty positive I'm using 2.3 at this
>> point.  The only issue is the @Before seems to never get called.
>>
>> Anyone run into this before?
>>
>> -aps
>>
>> On 5/23/07, Alexander Sack
>> wrote:
>> >
>> > Tom,
>> >
>> > Thanks sorry.  Yes I have specified in my root POM surefire-plugin 
>> 2.3but
>> > not in my submodule one (I will try that right now).  The test ource is
>> the
>> > one straight out of the FAQ regarding the colleciton, very simple test,
>> > passes on 3.8.1 but fails when I move up to 4.0 using the surefire
>> > plugin.  I'm using Junit-4.0.
>> >
>> > Is suppose to work?  The surefire report claims there is a null 
>> pointer:
>> >
>> > Here is my source:
>> >
>> > import static org.junit.Assert.* ;
>> >
>> > import java.util.ArrayList;
>> > import java.util.Collection;
>> >
>> > import org.junit.Before;
>> > import org.junit.Test;
>> >
>> > public class MyTest  {
>> >     private Collection c;
>> >
>> >     @Before
>> >     public void setUp() {
>> >         c = new ArrayList();
>> >     }
>> >
>> >     @Test
>> >     public void testSomeMethod() {
>> >         assertTrue(c.isEmpty());
>> >     }
>> > }
>> >
>> > Claims c is null which it isn't provided @Before runs (if I eliminate
>> the
>> > method and put it in my testSomeMethod() it passes.  How can I tell 
>> what
>> > version of surefire I'm running?  The -e just says that test case has
>> > failed, etc stack.
>> >
>> > What am I doing wrong?  (man, I've used maven2 in all kinds of advanced
>> > ways and I feel retarded that this is not working!).
>> >
>> > -aps
>> >
>> > On 5/23/07, Tom Huybrechts  wrote:
>> > >
>> > > would you mind sharing some more information ? POMs, exceptions, test
>> > > source,  -X output ?
>> > >
>> > > As a general remark: make sure you have the latest surefire plugin...
>> > >
>> > > Tom
>> > >
>> > > On 5/23/07, Alexander Sack < pisymbol@gmail.com> wrote:
>> > > > Hey folks, is this a known issue that if I use @Before it will fail
>> my
>> > > > test?  I searched some of the archives and saw some threads go by
>> > > about
>> > > > this.  Is this still an issue?
>> > > >
>> > > > Thanks!
>> > > >
>> > > > -aps
>> > > >
>> > > > --
>> > > > "What lies behind us and what lies in front of us is of little
>> concern
>> > > to
>> > > > what lies within us." -Ralph Waldo Emerson
>> > > >
>> > >
>> > > ---------------------------------------------------------------------
>> > > To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>> > > For additional commands, e-mail: users-help@maven.apache.org
>> > >
>> > >
>> >
>> >
>> > --
>> > "What lies behind us and what lies in front of us is of little concern
>> to
>> > what lies within us." -Ralph Waldo Emerson
>> >
>>
>>
>>
>> -- 
>> "What lies behind us and what lies in front of us is of little concern to
>> what lies within us." -Ralph Waldo Emerson
>>
>>
>>
> 
> 


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


Re: JUnit4 test cases using @Before, @After fail test?

Posted by Alexander Sack <pi...@gmail.com>.
Dennis, thanks for the tip.  Kinda obvious too...damn...

Okay, so can someone tell me what I need to do to FORCE it to use junit4?  I
specific junit-4.0 in my dependencies (scope is "test").  My parent dom of
the whole project has surefire plugin version set to 2.3.  I mean what else
do I have to do at this point?

-aps

On 5/23/07, Dennis Cook <dj...@yahoo.com> wrote:
>
> It looks like junit 3.8 is still being used.  The reason the method name
> prefix with 'test' will be called by the older version.  The annotation is
> probably ignored.  Change the name of the test method to another prefix, and
> I bet it will not be executed.
>
> Alexander Sack <pi...@gmail.com> wrote: Btw, considering that @Test
> works, I'm pretty positive I'm using 2.3 at this
> point.  The only issue is the @Before seems to never get called.
>
> Anyone run into this before?
>
> -aps
>
> On 5/23/07, Alexander Sack
> wrote:
> >
> > Tom,
> >
> > Thanks sorry.  Yes I have specified in my root POM surefire-plugin 2.3but
> > not in my submodule one (I will try that right now).  The test ource is
> the
> > one straight out of the FAQ regarding the colleciton, very simple test,
> > passes on 3.8.1 but fails when I move up to 4.0 using the surefire
> > plugin.  I'm using Junit-4.0.
> >
> > Is suppose to work?  The surefire report claims there is a null pointer:
> >
> > Here is my source:
> >
> > import static org.junit.Assert.* ;
> >
> > import java.util.ArrayList;
> > import java.util.Collection;
> >
> > import org.junit.Before;
> > import org.junit.Test;
> >
> > public class MyTest  {
> >     private Collection c;
> >
> >     @Before
> >     public void setUp() {
> >         c = new ArrayList();
> >     }
> >
> >     @Test
> >     public void testSomeMethod() {
> >         assertTrue(c.isEmpty());
> >     }
> > }
> >
> > Claims c is null which it isn't provided @Before runs (if I eliminate
> the
> > method and put it in my testSomeMethod() it passes.  How can I tell what
> > version of surefire I'm running?  The -e just says that test case has
> > failed, etc stack.
> >
> > What am I doing wrong?  (man, I've used maven2 in all kinds of advanced
> > ways and I feel retarded that this is not working!).
> >
> > -aps
> >
> > On 5/23/07, Tom Huybrechts  wrote:
> > >
> > > would you mind sharing some more information ? POMs, exceptions, test
> > > source,  -X output ?
> > >
> > > As a general remark: make sure you have the latest surefire plugin...
> > >
> > > Tom
> > >
> > > On 5/23/07, Alexander Sack < pisymbol@gmail.com> wrote:
> > > > Hey folks, is this a known issue that if I use @Before it will fail
> my
> > > > test?  I searched some of the archives and saw some threads go by
> > > about
> > > > this.  Is this still an issue?
> > > >
> > > > Thanks!
> > > >
> > > > -aps
> > > >
> > > > --
> > > > "What lies behind us and what lies in front of us is of little
> concern
> > > to
> > > > what lies within us." -Ralph Waldo Emerson
> > > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> > > For additional commands, e-mail: users-help@maven.apache.org
> > >
> > >
> >
> >
> > --
> > "What lies behind us and what lies in front of us is of little concern
> to
> > what lies within us." -Ralph Waldo Emerson
> >
>
>
>
> --
> "What lies behind us and what lies in front of us is of little concern to
> what lies within us." -Ralph Waldo Emerson
>
>
>


-- 
"What lies behind us and what lies in front of us is of little concern to
what lies within us." -Ralph Waldo Emerson

Re: JUnit4 test cases using @Before, @After fail test?

Posted by Dennis Cook <dj...@yahoo.com>.
It looks like junit 3.8 is still being used.  The reason the method name prefix with 'test' will be called by the older version.  The annotation is probably ignored.  Change the name of the test method to another prefix, and I bet it will not be executed.

Alexander Sack <pi...@gmail.com> wrote: Btw, considering that @Test works, I'm pretty positive I'm using 2.3 at this
point.  The only issue is the @Before seems to never get called.

Anyone run into this before?

-aps

On 5/23/07, Alexander Sack 
 wrote:
>
> Tom,
>
> Thanks sorry.  Yes I have specified in my root POM surefire-plugin 2.3 but
> not in my submodule one (I will try that right now).  The test ource is the
> one straight out of the FAQ regarding the colleciton, very simple test,
> passes on 3.8.1 but fails when I move up to 4.0 using the surefire
> plugin.  I'm using Junit-4.0.
>
> Is suppose to work?  The surefire report claims there is a null pointer:
>
> Here is my source:
>
> import static org.junit.Assert.* ;
>
> import java.util.ArrayList;
> import java.util.Collection;
>
> import org.junit.Before;
> import org.junit.Test;
>
> public class MyTest  {
>     private Collection c;
>
>     @Before
>     public void setUp() {
>         c = new ArrayList();
>     }
>
>     @Test
>     public void testSomeMethod() {
>         assertTrue(c.isEmpty());
>     }
> }
>
> Claims c is null which it isn't provided @Before runs (if I eliminate the
> method and put it in my testSomeMethod() it passes.  How can I tell what
> version of surefire I'm running?  The -e just says that test case has
> failed, etc stack.
>
> What am I doing wrong?  (man, I've used maven2 in all kinds of advanced
> ways and I feel retarded that this is not working!).
>
> -aps
>
> On 5/23/07, Tom Huybrechts  wrote:
> >
> > would you mind sharing some more information ? POMs, exceptions, test
> > source,  -X output ?
> >
> > As a general remark: make sure you have the latest surefire plugin...
> >
> > Tom
> >
> > On 5/23/07, Alexander Sack < pisymbol@gmail.com> wrote:
> > > Hey folks, is this a known issue that if I use @Before it will fail my
> > > test?  I searched some of the archives and saw some threads go by
> > about
> > > this.  Is this still an issue?
> > >
> > > Thanks!
> > >
> > > -aps
> > >
> > > --
> > > "What lies behind us and what lies in front of us is of little concern
> > to
> > > what lies within us." -Ralph Waldo Emerson
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> > For additional commands, e-mail: users-help@maven.apache.org
> >
> >
>
>
> --
> "What lies behind us and what lies in front of us is of little concern to
> what lies within us." -Ralph Waldo Emerson
>



-- 
"What lies behind us and what lies in front of us is of little concern to
what lies within us." -Ralph Waldo Emerson



Re: JUnit4 test cases using @Before, @After fail test?

Posted by Alexander Sack <pi...@gmail.com>.
Btw, considering that @Test works, I'm pretty positive I'm using 2.3 at this
point.  The only issue is the @Before seems to never get called.

Anyone run into this before?

-aps

On 5/23/07, Alexander Sack <pi...@gmail.com> wrote:
>
> Tom,
>
> Thanks sorry.  Yes I have specified in my root POM surefire-plugin 2.3 but
> not in my submodule one (I will try that right now).  The test ource is the
> one straight out of the FAQ regarding the colleciton, very simple test,
> passes on 3.8.1 but fails when I move up to 4.0 using the surefire
> plugin.  I'm using Junit-4.0.
>
> Is suppose to work?  The surefire report claims there is a null pointer:
>
> Here is my source:
>
> import static org.junit.Assert.* ;
>
> import java.util.ArrayList;
> import java.util.Collection;
>
> import org.junit.Before;
> import org.junit.Test;
>
> public class MyTest  {
>     private Collection<Object> c;
>
>     @Before
>     public void setUp() {
>         c = new ArrayList<Object>();
>     }
>
>     @Test
>     public void testSomeMethod() {
>         assertTrue(c.isEmpty());
>     }
> }
>
> Claims c is null which it isn't provided @Before runs (if I eliminate the
> method and put it in my testSomeMethod() it passes.  How can I tell what
> version of surefire I'm running?  The -e just says that test case has
> failed, etc stack.
>
> What am I doing wrong?  (man, I've used maven2 in all kinds of advanced
> ways and I feel retarded that this is not working!).
>
> -aps
>
> On 5/23/07, Tom Huybrechts <to...@gmail.com> wrote:
> >
> > would you mind sharing some more information ? POMs, exceptions, test
> > source,  -X output ?
> >
> > As a general remark: make sure you have the latest surefire plugin...
> >
> > Tom
> >
> > On 5/23/07, Alexander Sack < pisymbol@gmail.com> wrote:
> > > Hey folks, is this a known issue that if I use @Before it will fail my
> > > test?  I searched some of the archives and saw some threads go by
> > about
> > > this.  Is this still an issue?
> > >
> > > Thanks!
> > >
> > > -aps
> > >
> > > --
> > > "What lies behind us and what lies in front of us is of little concern
> > to
> > > what lies within us." -Ralph Waldo Emerson
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> > For additional commands, e-mail: users-help@maven.apache.org
> >
> >
>
>
> --
> "What lies behind us and what lies in front of us is of little concern to
> what lies within us." -Ralph Waldo Emerson
>



-- 
"What lies behind us and what lies in front of us is of little concern to
what lies within us." -Ralph Waldo Emerson

Re: JUnit4 test cases using @Before, @After fail test?

Posted by Alexander Sack <pi...@gmail.com>.
Tom,

Thanks sorry.  Yes I have specified in my root POM surefire-plugin 2.3 but
not in my submodule one (I will try that right now).  The test ource is the
one straight out of the FAQ regarding the colleciton, very simple test,
passes on 3.8.1 but fails when I move up to 4.0 using the surefire plugin.
I'm using Junit-4.0.

Is suppose to work?  The surefire report claims there is a null pointer:

Here is my source:

import static org.junit.Assert.*;

import java.util.ArrayList;
import java.util.Collection;

import org.junit.Before;
import org.junit.Test;

public class MyTest  {
    private Collection<Object> c;

    @Before
    public void setUp() {
        c = new ArrayList<Object>();
    }

    @Test
    public void testSomeMethod() {
        assertTrue(c.isEmpty());
    }
}

Claims c is null which it isn't provided @Before runs (if I eliminate the
method and put it in my testSomeMethod() it passes.  How can I tell what
version of surefire I'm running?  The -e just says that test case has
failed, etc stack.

What am I doing wrong?  (man, I've used maven2 in all kinds of advanced ways
and I feel retarded that this is not working!).

-aps

On 5/23/07, Tom Huybrechts <to...@gmail.com> wrote:
>
> would you mind sharing some more information ? POMs, exceptions, test
> source,  -X output ?
>
> As a general remark: make sure you have the latest surefire plugin...
>
> Tom
>
> On 5/23/07, Alexander Sack <pi...@gmail.com> wrote:
> > Hey folks, is this a known issue that if I use @Before it will fail my
> > test?  I searched some of the archives and saw some threads go by about
> > this.  Is this still an issue?
> >
> > Thanks!
> >
> > -aps
> >
> > --
> > "What lies behind us and what lies in front of us is of little concern
> to
> > what lies within us." -Ralph Waldo Emerson
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>


-- 
"What lies behind us and what lies in front of us is of little concern to
what lies within us." -Ralph Waldo Emerson

Re: JUnit4 test cases using @Before, @After fail test?

Posted by Tom Huybrechts <to...@gmail.com>.
would you mind sharing some more information ? POMs, exceptions, test
source,  -X output ?

As a general remark: make sure you have the latest surefire plugin...

Tom

On 5/23/07, Alexander Sack <pi...@gmail.com> wrote:
> Hey folks, is this a known issue that if I use @Before it will fail my
> test?  I searched some of the archives and saw some threads go by about
> this.  Is this still an issue?
>
> Thanks!
>
> -aps
>
> --
> "What lies behind us and what lies in front of us is of little concern to
> what lies within us." -Ralph Waldo Emerson
>

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