You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by "Edelson, Justin" <Ju...@mtvstaff.com> on 2008/10/29 21:26:07 UTC

Re: Maven + Junit 4.5 dependency does not work

I could be wrong about this, but I think with JUnit 4, you can either extend TestCase or use annotations, but not both. Try removing 'extends TestCase'

Justin 

----- Original Message -----
From: Petr V. <gr...@yahoo.com>
To: users@maven.apache.org <us...@maven.apache.org>
Sent: Wed Oct 29 16:14:54 2008
Subject: Maven + Junit 4.5 dependency does not work 

I must be doing some thing very silly :-(

I have this very simple test in maven project test directory. I have dependency on junit-4.5 and junit-util-4.5 in my pom file


import java.io.IOException;
import java.util.ArrayList;

import org.junit.Test;
import junit.framework.TestCase;

public class AppTest extends TestCase
{
   
    @Test
    public void testApp()
    {
        assertTrue( true );
    }
    
    @Test(expected=IndexOutOfBoundsException.class)
     public void testOutOfBounds() {
        new ArrayList<Object>().get(1);
     }
  
}

When I issue maven package command then my tests fail saying

Tests run: 2, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.063 sec <<< FAILURE!
testOutOfBounds(com.xx.AppTest)  Time elapsed: 0 sec  <<< ERROR!
java.lang.IndexOutOfBoundsException: Index: 1, Size: 0
    at java.util.ArrayList.RangeCheck(ArrayList.java:547)
    at java.util.ArrayList.get(ArrayList.java:322)
    at com.xx.AppTest.testOutOfBounds(AppTest.java:45)

I have asked via annotation that I am expecting exception but it is not caught, why this is happening ? it simply ignores the following line of code
 @Test(expected=IndexOutOfBoundsException.class)

Any idea what am I doing wrong, I am sure it is one of those silly things which make you cry :-(

Thanks,

Petr  



      

Re: Maven + Junit 4.5 dependency does not work

Posted by Wayne Fay <wa...@gmail.com>.
> Actually annotations are completely ignored. I put the @Test in front of test but function name did not start with prefix "test" and it was not executed at all.

Just covering the obvious... you have configured the source 1.5 and
target 1.5 in the compiler plugin in your pom, right?

Wayne

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


RE: Maven + Junit 4.5 dependency does not work

Posted by "Edelson, Justin" <Ju...@mtvstaff.com>.
Other than ensuring, as Wayne said, that your compiling correctly, not much. This class worked fine for me under Junit 4.5:

package test;

import static org.junit.Assert.*;

import java.util.ArrayList;

import org.junit.Test;

public class AppTest {
    @Test
    public void testApp() {
        assertTrue(true);
    }

    @Test(expected = IndexOutOfBoundsException.class)
    public void testOutOfBounds() {
        new ArrayList<Object>().get(1);
    }

    @Test
    public void app() {
        assertTrue(true);
    }

    @Test(expected = IndexOutOfBoundsException.class)
    public void outOfBounds() {
        new ArrayList<Object>().get(1);
    }
}

 

-----Original Message-----
From: Petr V. [mailto:greatman787@yahoo.com] 
Sent: Wednesday, October 29, 2008 4:38 PM
To: Maven Users List
Subject: Re: Maven + Junit 4.5 dependency does not work

I removed extends TestCase but same result, it did not help.

Actually annotations are completely ignored. I put the @Test in front of test but function name did not start with prefix "test" and it was not executed at all. 

I thought if you put the annotation @Test then you don't need to prefix your test function with "test". Some thing is really going bad ..

Any more pointers ?

Thanks,

Petr


--- On Thu, 10/30/08, Edelson, Justin <Ju...@mtvstaff.com> wrote:
From: Edelson, Justin <Ju...@mtvstaff.com>
Subject: Re: Maven + Junit 4.5 dependency does not work
To: users@maven.apache.org
Date: Thursday, October 30, 2008, 1:26 AM

I could be wrong about this, but I think with JUnit 4, you can either extend TestCase or use annotations, but not both. Try removing 'extends TestCase'

Justin 

----- Original Message -----
From: Petr V. <gr...@yahoo.com>
To: users@maven.apache.org <us...@maven.apache.org>
Sent: Wed Oct 29 16:14:54 2008
Subject: Maven + Junit 4.5 dependency does not work 

I must be doing some thing very silly :-(

I have this very simple test in maven project test directory. I have dependency on junit-4.5 and junit-util-4.5 in my pom file


import java.io.IOException;
import java.util.ArrayList;

import org.junit.Test;
import junit.framework.TestCase;

public class AppTest extends TestCase
{
   
    @Test
    public void testApp()
    {
        assertTrue( true );
    }
    
    @Test(expected=IndexOutOfBoundsException.class)
     public void testOutOfBounds() {
        new ArrayList<Object>().get(1);
     }
  
}

When I issue maven package command then my tests fail saying

Tests run: 2, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.063 sec <<< FAILURE!
testOutOfBounds(com.xx.AppTest)  Time elapsed: 0 sec  <<< ERROR!
java.lang.IndexOutOfBoundsException: Index: 1, Size: 0
    at java.util.ArrayList.RangeCheck(ArrayList.java:547)
    at java.util.ArrayList.get(ArrayList.java:322)
    at com.xx.AppTest.testOutOfBounds(AppTest.java:45)

I have asked via annotation that I am expecting exception but it is not caught, why this is happening ? it simply ignores the following line of code
 @Test(expected=IndexOutOfBoundsException.class)

Any idea what am I doing wrong, I am sure it is one of those silly things which make you cry :-(

Thanks,

Petr  



      



      

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


Re: Maven + Junit 4.5 dependency does not work

Posted by "Petr V." <gr...@yahoo.com>.
I removed extends TestCase but same result, it did not help.

Actually annotations are completely ignored. I put the @Test in front of test but function name did not start with prefix "test" and it was not executed at all. 

I thought if you put the annotation @Test then you don't need to prefix your test function with "test". Some thing is really going bad ..

Any more pointers ?

Thanks,

Petr


--- On Thu, 10/30/08, Edelson, Justin <Ju...@mtvstaff.com> wrote:
From: Edelson, Justin <Ju...@mtvstaff.com>
Subject: Re: Maven + Junit 4.5 dependency does not work
To: users@maven.apache.org
Date: Thursday, October 30, 2008, 1:26 AM

I could be wrong about this, but I think with JUnit 4, you can either extend
TestCase or use annotations, but not both. Try removing 'extends
TestCase'

Justin 

----- Original Message -----
From: Petr V. <gr...@yahoo.com>
To: users@maven.apache.org <us...@maven.apache.org>
Sent: Wed Oct 29 16:14:54 2008
Subject: Maven + Junit 4.5 dependency does not work 

I must be doing some thing very silly :-(

I have this very simple test in maven project test directory. I have dependency
on junit-4.5 and junit-util-4.5 in my pom file


import java.io.IOException;
import java.util.ArrayList;

import org.junit.Test;
import junit.framework.TestCase;

public class AppTest extends TestCase
{
   
    @Test
    public void testApp()
    {
        assertTrue( true );
    }
    
    @Test(expected=IndexOutOfBoundsException.class)
     public void testOutOfBounds() {
        new ArrayList<Object>().get(1);
     }
  
}

When I issue maven package command then my tests fail saying

Tests run: 2, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.063 sec
<<< FAILURE!
testOutOfBounds(com.xx.AppTest)  Time elapsed: 0 sec  <<< ERROR!
java.lang.IndexOutOfBoundsException: Index: 1, Size: 0
    at java.util.ArrayList.RangeCheck(ArrayList.java:547)
    at java.util.ArrayList.get(ArrayList.java:322)
    at com.xx.AppTest.testOutOfBounds(AppTest.java:45)

I have asked via annotation that I am expecting exception but it is not caught,
why this is happening ? it simply ignores the following line of code
 @Test(expected=IndexOutOfBoundsException.class)

Any idea what am I doing wrong, I am sure it is one of those silly things which
make you cry :-(

Thanks,

Petr