LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-21-2005, 12:26 PM   #1
Hockeyfan
Member
 
Registered: May 2004
Distribution: SuSe 10.0
Posts: 154

Rep: Reputation: 30
Test-Driven Development question


I have had this nagging question about Test-Driven Development. How do I test methods that are considered void methods? Well methods that actually do something other then sets a value.

I am using JUnit and JDK 1.5 to do my coding.

While I was in school I was exposed to this type of development but I wasn't able to fully grasp it for a number of reasons. This being one of them. This is not a class project, its something I am doing on my own.

Hockeyfan
 
Old 02-22-2005, 12:03 AM   #2
eric.r.turner
Member
 
Registered: Aug 2003
Location: Planet Earth
Distribution: Linux Mint
Posts: 216

Rep: Reputation: 31
void methods by definition have side effects (otherwise there is NO point in having them!) You need to check the side effect. For example, if you have a void method that inserts data into a database then your unit tests should verify that. If you expect your method to throw exceptions, then you should write unit tests for those as well.
 
Old 02-22-2005, 04:21 AM   #3
ChemicalBurn
LQ Newbie
 
Registered: Feb 2005
Posts: 28

Rep: Reputation: 15
Like eric said, your method is there for a reason, simply test out the result of the method. If you're setting the value, simply add a printout line of that value to make sure it works, then remove it after...
 
Old 02-26-2005, 03:55 PM   #4
Hockeyfan
Member
 
Registered: May 2004
Distribution: SuSe 10.0
Posts: 154

Original Poster
Rep: Reputation: 30
Does anyone know how to test conditional statements using JUnit. I have been able to test retun values but I also want to be able to create a test that tests the truth value of an if statement. I believe I've seen it before but I can't remember how to do it.

Thanks

Hockeyfan
 
Old 03-03-2005, 03:58 AM   #5
machron1
Member
 
Registered: Mar 2005
Posts: 34

Rep: Reputation: 15
The whole deal with JUnit is you use its Assert(...) methods. When an assertion fails, that test fails.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Gnome Applet Development Question firefly2442 Linux - Software 1 09-10-2005 05:07 PM
database driven site (egrade) rksprst General 3 06-27-2005 04:51 PM
Community driven advertisment? Caboose General 4 04-10-2005 06:24 PM
Development Evironment Question gordingin Programming 1 09-29-2004 12:55 PM
dselect menu-driven GUI mullog Programming 1 06-14-2004 03:44 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:29 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration