aspose file tools*
The moose likes Testing and the fly likes Exception when using setup() in a junit testcase Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "Exception when using setup() in a junit testcase" Watch "Exception when using setup() in a junit testcase" New topic
Author

Exception when using setup() in a junit testcase

Kamal Ahmed
Ranch Hand

Joined: Feb 15, 2005
Posts: 91
Hi List,

I have a rather basic question regarding junit/eclipse.

When I run the following class as a junit test in eclipse, it works ok


But when I have a setup method, like:

I get exception:



You have any ideas?

Thanks,

-Kamal.


(EDIT: edited the post to use UBB code tags)
[ January 24, 2006: Message edited by: Lasse Koskela ]
Eric Nielsen
Ranch Hand

Joined: Dec 14, 2004
Posts: 194
You have to use setUp() not setup() as the method name. With your current name, the test runner code isn't calling the test fixture initialization code and therefore you get the null pointer exception.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Exception when using setup() in a junit testcase
 
Similar Threads
StrutsTestCase problem
Junit error
NULL Pointer Exception
Can't run JUnit 4 test in Eclipse
Junit test: cannot find test Method although that it is already defined in the test class