• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SetUp getting called for every test method

 
Adam Teg
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author & internet detective
Marshal
Posts: 34656
366
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Adam Teg
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I load files in that method and I don't want to do it every time.

Thanks
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic