File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Trouble using addTestSuite() vs. addTest()

 
Russell Bateman
Ranch Hand
Posts: 69
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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>Test.java files matching my classes in com.myapp.utils, which run fine, and also a UtilsTestSuite.java. Launching UtilsTestSuite as a JUnit Test is successful too; it runs the various <class>Test.java 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 AllTests.java (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
author
Sheriff
Posts: 14112
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

addTest(UtilsTestSuite.suite());
 
Russell Bateman
Ranch Hand
Posts: 69
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks much, Ilja.
 
Russell Bateman
Ranch Hand
Posts: 69
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:

http://www.windofkeltia.com/j2ee/junit.html

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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic