This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Testing and the fly likes JUnit testing void methods Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "JUnit testing void methods" Watch "JUnit testing void methods" New topic

JUnit testing void methods

Mark Miranda

Joined: Feb 25, 2011
Posts: 24

How can I write JUnit test cases for the Class below?

I put something together quickly, but that's basically the skeleton for the program i'm going to write...

I'm still fairly new to JUnit

Pawel Piwowar

Joined: Feb 12, 2010
Posts: 21

Your findCar() method must return something, should not be void.
Since you fix this, the class could be tested with code like that:

You can create similar tests for other methods.
Repeating code, like creating new instance of ParkingLot could be moved to separate method annotated with @Before

SCJP 5, SCWCD 1.4, SCBCD 5, SCEA part1
I agree. Here's the link:
subject: JUnit testing void methods
Similar Threads
Exception "javax.persistence.EntityNotFoundException: Unable to find ParkingSpace with 3
One to One mapping in Hibernate 3
Help with ArrayList error
Usefulness of assigning an object to an interface reference variable?