aspose file tools*
The moose likes Beginning Java and the fly likes Testing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Testing" Watch "Testing" New topic
Author

Testing

Maureen Charlton
Ranch Hand

Joined: Oct 04, 2004
Posts: 218
Could someone clarify the correct way to test something, for the benefit of handing in assingments.

Is it to write another class/program and ensure all the posibilities have been entered and tested?

Or is it sufficient to have println's in the actual methods of the class to confirm that what is expected is actually happening?

Which is the preferred method in the real world and for assignments?
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Unit Testing (which I assume you mean, rather than System, Integration, Regression testing etc. ) is usually done on the basis of one test per business method. What would happen is suppose you write a class called DoesSomething which has five public business methods then typically you'd have a TestDoesSomething which calls each method and verifies what they return is what is expected and they handle potential garbage data correctly.


Or is it sufficient to have println's in the actual methods of the class to confirm that what is expected is actually happening?

Normally no. You need tests which work on the basis of assertions. You need to programmatically check things are OK, since eyeballing output is a very fallable and timeconsumming test.


There is a lot more written about this in the Testing forum than is probably appropriate to repeat here. I'd recommend you have a trawl through that. I'd also recommend you look at JUnit a commonly used unit test framework. That site has links to a lot of resources on this subject.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Maureen Charlton
Ranch Hand

Joined: Oct 04, 2004
Posts: 218
Paul,

Thank you very much.
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Writing the tests first is an exciting way to work. In another post we recommended someone start with this:

and THEN write the PhoneNumber class to make it work. It's a great way to make sure you understand what a method is supposed to do before you start it.

BTW: A test framework like JUnit replaces all that result testing and reporting with:

which serves as neat documentation and an example of how to use the class under test.

I'm pretty impressed by the question to start with. Go forth, test first, have fun!


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Testing