File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Testing and the fly likes SetUp getting called for every test method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Testing
Bookmark "SetUp getting called for every test method" Watch "SetUp getting called for every test method" New topic
Author

SetUp getting called for every test method

Adam Teg
Ranch Hand

Joined: Jul 10, 2007
Posts: 58
I have a junit test class. For everymethod I test it seems to call the SetUp method. How can I prevent this?
Thanks
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30537
    
150

Originally posted by James Steblay:
I have a junit test class. For everymethod I test it seems to call the SetUp method. How can I prevent this?
Thanks

That's how JUnit works. The tests are designed to be independent. What is the problem with setUp() getting called for each test?


[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
Adam Teg
Ranch Hand

Joined: Jul 10, 2007
Posts: 58
I load files in that method and I don't want to do it every time.

Thanks
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Accessing the file system typically isn't a very good idea for a unit test. You might want to consider alternatives.

If you really have to, the easiest solution would be to use JUnit 4.x and make use of the @BeforeClass annotation (if you are using Java 5 or later).


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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: SetUp getting called for every test method