aspose file tools
The moose likes Testing and the fly likes setUp and tearDown Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Engineering » Testing
Reply Bookmark "setUp and tearDown" Watch "setUp and tearDown" New topic
Author

setUp and tearDown

Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9033
    
  10
I thought that setUp was called before each testXxxx method and tearDown was called after each testXxxx method. However, when I try to initialize my object in setUp, I get a NullPointerException.


Am I doing something wrong? Am I misunderstanding the function of setUp and tearDown?
[ December 01, 2003: Message edited by: Marilyn de Queiroz ]

JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 26193
    
  66

Is it same to assume that you extending the TestCase class? And that the method itself isn't throwing the null pointer exception?
From a logical perspective, you are doing everything right. And the code looks fine.
[ December 01, 2003: Message edited by: Jeanne Boyarsky ]

[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9033
    
  10
Is it same to assume that you extending the TestCase class?

Yes.

And that the method itself isn't throwing the null pointer exception?

Yes.

The following code does not throw the exception.

Karthik Guru
Ranch Hand

Joined: Mar 06, 2001
Posts: 1209
This might be stupid. But could you tell us how you are running your test.
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Are you totally sure you got the method signature right? It once happened to me that I accidentally wrote setup() instead of setUp()...


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9033
    
  10
Thanks everyone. I must've mistyped something because I deleted those methods and retyped them and now everything works properly.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: setUp and tearDown
 
Similar Threads
JUnit fixture
Test duplication on db with exception...am I on the right track?
setUp and teardown not working
RMI over the Internet inc. Callbacks (Lipe RMI)
Problems with JUnit Tests