File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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
It's not a secret anymore!