• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Loading Common Data for testing using Junit

 
Greenhorn
Posts: 11
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am new to JUnit test cases. I am writing junit test case for one of the java batch program.

I need to load data from database to heap memory in order to run the test case. Right now i am using setUp() method to do this, but i need to repeat this for all the test cases which increases the time of testing and some times i get the heap space error.

My question is, can i load all the data required once and keep it on heap till all the test cases gets completed?

I couldn't find any help on net in this regard. Have anybody faced this situation and is there any method to overcome this?

Thanks

 
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As of JUnit 4 you can use @BeforeClass and @AfterClass to set up an expensive fixture shared by all test cases contained in that class.
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Supradeep,
There are two approaches. One is to use @BeforeClass/@AfterClass as Jelle mentioned. This works well if all the tests you want to run with that data are in the same class.

In my applications we have scores to hundreds of tests that use the same data so this is impractical. What we do is run a Java program with a main method. That main method does three things:
  • call method to load data
  • call JunitCore.run(MyTestSuite.class)
  • call method to unload data


  • This still gives the report on what passed/failed. It just does it in text form instead of visual form.
     
    Supradeep Makam
    Greenhorn
    Posts: 11
    Eclipse IDE Firefox Browser Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Jelle / Jeanne ,

    Thanks for your help. I am using @BeforeClass method for loading common data, this works fine now.
     
    reply
      Bookmark Topic Watch Topic
    • New Topic