• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Basic question on JUnit Test Suite

 
Schandha Ravi
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

This may sound very basic question related to JUnit Test Suite , but believe me I'm not able to understand it. As part of my project (For which I do not currently have access to do trial run), I was going through existing testing frame work and the flow is as below :

There is a base class extending TestCase say



But the above class does not have any methods beginning with test, so there are no Test methods and apparently when we run this class, we get a message that no tests found.



My question was, when would init() method be called as it is called from No-Arg constructor. Why is the statement return( new TestSuite( ParentTest.class ) );
there in ChildTestCase and apparently this should also throw an error as ParentTest does not have any methods beginning with test.

Can some one throw some light on this?

Thanks
Ravi
[ June 30, 2008: Message edited by: Schandha Ravi ]
 
Schandha Ravi
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can some one throw some light on my question? Please let me know if the information provided is not sufficient, so that I can try to provide some more.

Thanks
Ravi
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Frankly, that could is really strange and seems to come from someone who didn't understand how JUnit works. You should never write JUnit tests that way - even if it would work.
 
Schandha Ravi
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ilja for the update.

I'm just thinking if the method call for the method init() could be moved to Single argument constructor of ParentTest, then the usage of init() has some sense. Is this correct?

Also, please confirm if my understanding is correct. In this code, Zero argument constructor can never be called, as we have a single argument constructor.

Thanks
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I still can't figure out what you want to achieve by writing all that init() stuff yourself. JUnit already has a design that allows for pre-test (setUp) and post-test (tearDown) execution - why not use that?
 
Schandha Ravi
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,

My idea of using init() is to use reflection to load all the testcases into test suites() based on different conditions. So that I explicitly need not load each and every test case.

I actually did a small modification to the above programs and came up with a small design. Can you please let me know, if this approach is acceptable and extendable. Also please let me know, for any improvisations.





Is my code inducing any complexity and obstruction for future maintainance. Please advice me in better design approach.

Thanks
Ravi
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34851
369
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What should happen for tests that don't begin with "dev" or "prod" ?
 
Pat Farrell
Rancher
Posts: 4678
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't follow you. If you use a decent IDE, it will generate explicit test functions for each function in your class.

I think your reflection idea is just not good. When I let Netbeans make my tests, the first thing I do is look at them, and throw a bunch of tests away for things that are not important. I don't both to write explicit tests for each getFoo() and setFoo() when all they do is return the foo value.

IMHO, if you call setFoo("something") and then call getFoo() and don't get "something" back, you have far more serious problems.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would rather put the "dev" and "prod" tests into different classes, possibly even different source folders. Sound much less brittle and complicated to me. Your mileage may vary...
 
Schandha Ravi
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for all the inputs provided for my questions. It would be better if I could separate the concerns of test and prod environments in two different TestSuites .
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic