Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > JUnit 4 Test Suite - addTest not applicable?

Reply
Thread Tools

JUnit 4 Test Suite - addTest not applicable?

 
 
TheSouthLondonSlasher
Guest
Posts: n/a
 
      09-24-2008
I have a simple JUnit4 test, which I want to run from a testSuite,
since obviously, later we'll have many tests. So my test is:

package test.gg.ba.util;

import static org.junit.Assert.assertEquals;
import org.junit.Test;
import com.gg.ba.util.Utility;

public class UtilityTest {

@Test
public void testCheckNull() {
assertEquals(Utility.checkNull("Ham"), false);
}
}

This is fine and dandy, and works well when I run as JUnit Test in
Eclipse. However, the Suite, I'm having trouble with:

package test;

import test.gg.ba.util.UtilityTest;
import junit.framework.Test;
import junit.framework.TestSuite;

public class AllTests {

public static Test suite() {
TestSuite suite = new TestSuite("Test for test");
//$JUnit-BEGIN$

suite.addTest(test.gg.ba.util.UtilityTest.class);

//$JUnit-END$
return suite;
}
}

The line suite.addTest tells me:
The method addTest(Test) in the type TestSuite is not applicable for
the arguments (Class <UtilityTest>).

I understand what this message means, but all of the examples I find
do it this way, so I do not understand what the mistake I am making
is.

Any help will be greatly appreciated! Thank you in advance.
 
Reply With Quote
 
 
 
 
Arne Vajh°j
Guest
Posts: n/a
 
      10-06-2008
TheSouthLondonSlasher wrote:
> I have a simple JUnit4 test, which I want to run from a testSuite,
> since obviously, later we'll have many tests. So my test is:
>
> package test.gg.ba.util;
>
> import static org.junit.Assert.assertEquals;
> import org.junit.Test;
> import com.gg.ba.util.Utility;
>
> public class UtilityTest {
>
> @Test
> public void testCheckNull() {
> assertEquals(Utility.checkNull("Ham"), false);
> }
> }
>
> This is fine and dandy, and works well when I run as JUnit Test in
> Eclipse. However, the Suite, I'm having trouble with:
>
> package test;
>
> import test.gg.ba.util.UtilityTest;
> import junit.framework.Test;
> import junit.framework.TestSuite;
>
> public class AllTests {
>
> public static Test suite() {
> TestSuite suite = new TestSuite("Test for test");
> //$JUnit-BEGIN$
>
> suite.addTest(test.gg.ba.util.UtilityTest.class);
>
> //$JUnit-END$
> return suite;
> }
> }
>
> The line suite.addTest tells me:
> The method addTest(Test) in the type TestSuite is not applicable for
> the arguments (Class <UtilityTest>).
>
> I understand what this message means, but all of the examples I find
> do it this way, so I do not understand what the mistake I am making
> is.


You code above is all JUnit 3 code.

Remove all imports of junit.framework.* and use annotations.

The relevant one is:

@SuiteClasses( { Utility.class }).

Arne
 
Reply With Quote
 
 
 
 
Arne Vajh°j
Guest
Posts: n/a
 
      10-06-2008
Arne Vajh°j wrote:
> TheSouthLondonSlasher wrote:
>> I have a simple JUnit4 test, which I want to run from a testSuite,
>> since obviously, later we'll have many tests. So my test is:
>>
>> package test.gg.ba.util;
>>
>> import static org.junit.Assert.assertEquals;
>> import org.junit.Test;
>> import com.gg.ba.util.Utility;
>>
>> public class UtilityTest {
>>
>> @Test
>> public void testCheckNull() {
>> assertEquals(Utility.checkNull("Ham"), false);
>> }
>> }
>>
>> This is fine and dandy, and works well when I run as JUnit Test in
>> Eclipse. However, the Suite, I'm having trouble with:
>>
>> package test;
>>
>> import test.gg.ba.util.UtilityTest;
>> import junit.framework.Test;
>> import junit.framework.TestSuite;
>>
>> public class AllTests {
>>
>> public static Test suite() {
>> TestSuite suite = new TestSuite("Test for test");
>> //$JUnit-BEGIN$
>>
>> suite.addTest(test.gg.ba.util.UtilityTest.class);
>>
>> //$JUnit-END$
>> return suite;
>> }
>> }
>>
>> The line suite.addTest tells me:
>> The method addTest(Test) in the type TestSuite is not applicable for
>> the arguments (Class <UtilityTest>).
>>
>> I understand what this message means, but all of the examples I find
>> do it this way, so I do not understand what the mistake I am making
>> is.

>
> You code above is all JUnit 3 code.
>
> Remove all imports of junit.framework.* and use annotations.
>
> The relevant one is:
>
> @SuiteClasses( { Utility.class }).


Let me give an example.

First two test classes:

import static org.junit.Assert.*;

import org.junit.Test;

public class JU1 {
@Test
public void test1() {
assertNotNull("ABC");
}
}

and

package october;

import static org.junit.Assert.*;

import org.junit.Test;

public class JU2 {
@Test
public void test1() {
assertNotNull("ABC");
}
}

and now a suite:

package october;

import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;

@RunWith(Suite.class)
@SuiteClasses({JU1.class,JU2.class})
public class AllJU {
}

Arne
 
Reply With Quote
 
jbo
Guest
Posts: n/a
 
      10-07-2008
Hi !
Should one manually list test classes in @SuiteClasses ?
Is there no supprt from Eclipse plugin?

regards
-Jarek

> @RunWith(Suite.class)
> @SuiteClasses({JU1.class,JU2.class})

 
Reply With Quote
 
Arne Vajh°j
Guest
Posts: n/a
 
      10-07-2008
jbo wrote:
> Should one manually list test classes in @SuiteClasses ?
> Is there no supprt from Eclipse plugin?


I don't know.

But considering that:
1) it is perfectly valid to have a suite that only run some
of the tests in the package
2) in JUnit 3.x you would need to specify the classes
in the code
then I really doubt there are any magic in Eclipse.

Arne
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
test-all test suite fails upon Ruby 1.8.5 compilation D. Krmpotic Ruby 4 08-03-2007 01:20 AM
Where to put JUnit test cases? Ken Java 2 07-16-2004 04:02 AM
Junit Test From Ant--java.lang.LinkageError Tom Koenning Java 0 07-28-2003 07:11 PM
test test test test test test test Computer Support 2 07-02-2003 06:02 PM



Advertisments