• 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

setUp and teardown not working

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have many tests and want to use a suite to help me organize them. When I use the suite to run the tests the setup is not getting run. I have a separate class that I want to be the suite class that runs all my test classes. The setup and teardown methods are in my test classes. So my suite class looks like this:



My TestAdd, TestModify, TestDelete classes have the setup and teardown methods in them, but those methods don't get run when I run my AllTests class. Why not? Do I need to structure something differently, if so where do I put setup() and teardown()? I also use @BeforeClass and @AfterClass, but figured I'd tackle one thing at a time. Please help.

Thanks in advance,
JSpike

BTW - I'm running these junit tests in Eclipse.
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. Which version of JUnit are you using ?
2. Are you methods called when only a test class is executed ? (without the suite)
3. In JUnit 3.x, the setup method is called "setUp", not "setup". Same for tearDown. It's "tearDown", not "teardown"
 
J Spike
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Christophe Verré wrote:1. Which version of JUnit are you using ?
2. Are you methods called when only a test class is executed ? (without the suite)
3. In JUnit 3.x, the setup method is called "setUp", not "setup". Same for tearDown. It's "tearDown", not "teardown"



I'm using JUnit 4. When the test class is executed, everything works the way it should. I use the annotation @Before and @After for my setup and teardown methods, however I have kept the name the same. Here's a snippet of what the class looks like:



All required libraries are imported. There are numerous tests that get run, this is an example of the structure of the class.

Thanks again for your replies and help.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. In TestAddIPTG, remove "extends TestCase". You don't need it with JUnit4.
2. Change your suite to look like this:
 
J Spike
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Christophe, that did the trick.
All tests are running now with before and after methods working. Thanks!
 
My cellmate was this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic