Group: comp.lang.java.programmer
From: dom.k.black@googlemail.com
Date: Tuesday, March 25, 2008 3:01 AM
Subject: Re: JUnit 4.4 expected exception not working?

On Mar 24, 11:53 pm, Owen Jacobson wrote:
> On Mar 24, 6:34 pm, dom.k.bl...@googlemail.com wrote:
>
>
>
> > On 24 Mar, 22:12, Patricia Shanahan wrote:
>
> > > dom.k.bl...@googlemail.com wrote:
> > > > I am fairly new to JUnit so maybe I did something silly here.
>
> > > > I have the following in a test case:
>
> > > > @Test (expected=ArrayIndexOutOfBoundsException.class)
> > > > public void testOutOfRangeChannel() {
> > > > throw new ArrayIndexOutOfBoundsException();
> > > > }
>
> > > > When I run the test case I get an error, due to the exception. The
> > > > trace is:
>
> > > Are you sure you are running the right JUnit version?
>
> > > I tried copying the sample code into one of my own tests, and it ran
> > > successfully, no exception trace. The problem has to be in which JUnit
> > > version you are running how, not in the actual test case.
>
> > > Patricia
>
> > Thanks for confirming this. Maybe I picked up a dodgy beta JUnit
> > version. I will try a different one.
>
> Note that if your test suite is a class derived from TestCase or
> TestSuite, JUnit 4 will run it "as if" under JUnit 3's rules, in which
> case any exception is an error, and @Test is ignored entirely. To use
> the JUnit 4 features, your class should be derived from Object -- and
> you don't need to name your test cases testSomething, just something,
> provided they're correctly annotated.
>
> -o

Thanks, that might be it.

I changed the class to be derived from TestCase.

But if I don't do that, I can add the test to the AllTests test suite
(addSuite needsa TestCase subclass)?

News in English | Binaries Groups | 20lbs in 30 days