File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Testing and the fly likes Trouble using addTestSuite() vs. addTest() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Testing
Bookmark "Trouble using addTestSuite() vs. addTest()" Watch "Trouble using addTestSuite() vs. addTest()" New topic

Trouble using addTestSuite() vs. addTest()

Russell Bateman
Ranch Hand

Joined: Feb 26, 2008
Posts: 69
So, I too am a newbie to JUnit.

I believe my problem may be due in part to some hierarchy in my application. I have com.myapp.utils, com.myapp.archive, etc. plus other com.somethingelse.authentication, etc. I'm trying to retrofit all of this with JUnit tests following the package path hierarchy.

I've created some <class> files matching my classes in com.myapp.utils, which run fine, and also a Launching UtilsTestSuite as a JUnit Test is successful too; it runs the various <class> tests it gathers together. So far, so good.

In com.myapp (so, one level up), I've created a ServerClassesTestSuite (see code below in case it's any help) and called addTestSuite( UtilsTestSuite.class ) and I intend to add others (ArchiveTestSuite.class, etc.), but running it I get an error:

junit.framework.AssertionFailedError: No tests found in com.myapp.utils.UtilsTestSuite

My intention is to create (maybe I'm naive here) to unite ServerClassesTestSuite and others I have yet to write at the same level.

What's more...

The subject of this plea for help reveals that I don't completely grok the distinction between addTestSuite() and addTest(). Believe me, I've read pretty much every JUnit tutorial I've found on Google, most barely acknowledge the existence of TestSuite. The one that does gives an example, which I've followed here in ServerClassesTestSuite, but comment out the call to addTest() and don't even give sample code for what's passed to it as an argument. Yet, I figure, this addTestSuite()/addTest() is likely not even my problem.

Thanks for the help anyone can give,

Russ Bateman

Here's some of my code--dumbed way down to fit in here.

Ilja Preuss

Joined: Jul 11, 2001
Posts: 14112
Yeah, addTestSuite really is a bit of a misnomer - you don't use it to add a TestSuite (doh!), but to add a single Test*Class* as a TestSuite. If you take a look at the source code, you will see that it's jsut a shortcut for

addTest(new TestSuite(testClass));

To really add an already existing TestSuite, use


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Russell Bateman
Ranch Hand

Joined: Feb 26, 2008
Posts: 69
Thanks much, Ilja.
Russell Bateman
Ranch Hand

Joined: Feb 26, 2008
Posts: 69
Okay, I've got my deeply hierarchical test framework going.

To give back a little here by presenting a different view than the tutorials I found and read, here's my take for anyone who wants to see a bit more code, corrected, than what I put above, plus lots of comments, some of which may be totally in error:

Caveat: This is not going to be much use to anyone who isn't reading the tutorials, however, because I'm not trying to write a tutorial. I link to two tutorials in this document.
I agree. Here's the link:
subject: Trouble using addTestSuite() vs. addTest()
It's not a secret anymore!