File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Testing and the fly likes Basic question on JUnit Test Suite Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Testing
Bookmark "Basic question on JUnit Test Suite" Watch "Basic question on JUnit Test Suite" New topic
Author

Basic question on JUnit Test Suite

Schandha Ravi
Ranch Hand

Joined: Oct 20, 2007
Posts: 167
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 ]

Thanks & Regards, SK
SCJP 5.0, DB2 - 800, DB2 - 803, SCDJWS (On the way)
Schandha Ravi
Ranch Hand

Joined: Oct 20, 2007
Posts: 167
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

Joined: Jul 11, 2001
Posts: 14112
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.


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
Schandha Ravi
Ranch Hand

Joined: Oct 20, 2007
Posts: 167
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

Joined: Jan 23, 2002
Posts: 11962
    
    5
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?


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Schandha Ravi
Ranch Hand

Joined: Oct 20, 2007
Posts: 167
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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30510
    
150

What should happen for tests that don't begin with "dev" or "prod" ?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4655
    
    5

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

Joined: Jul 11, 2001
Posts: 14112
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

Joined: Oct 20, 2007
Posts: 167
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 .
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Basic question on JUnit Test Suite