GroovyTestCase runs all setUp()?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

GroovyTestCase runs all setUp()?

SiKing

Hi all.

I am a relative newb to the entire Java world, and I jumped into Groovy head first.

I am building up a test suite, and as my first attempt I did everything in JUnit4. Everything went fine.

I then discovered GroovyTestCase, and tried to redo everything to be more Groovy. I am facing one issue: I have one class (I call it GenericSetupTeardown) that extends GroovyTestCase and this is where I override setUp() and tearDown(). All my test classes then extend from my GenericSetupTeardown. When I run my test suite (class), it appears that setUp() gets run first for every test in that class, followed by the tests themselves! So if I have:

class SampleGroovyTCTestSuite extends GenericSetupTeardown {
   void test_FirstSample() {
      ...
   }
   void test_FirstSample() {
      ...
   }
}

I get two setUp() executed, followed by test_FirstSample(), followed by tearDown(), followed by test_FirstSample(), followed by tearDown().

Is this the correct behaviour, or am I just way off?

All the code is at sourceforge.net if it helps.

TIA for any advice.

Reply | Threaded
Open this post in threaded view
|

Re: GroovyTestCase runs all setUp()?

lam nguyen phuc
This is the expected behavior for every JUnit test case. The setUp() / tearDown() methods are called fixture methods and are executed before and after each test method, respectively. 

On Thu, Sep 29, 2011 at 12:33 AM, SiKing <[hidden email]> wrote:

Hi all.

I am a relative newb to the entire Java world, and I jumped into Groovy head first.

I am building up a test suite, and as my first attempt I did everything in JUnit4. Everything went fine.

I then discovered GroovyTestCase, and tried to redo everything to be more Groovy. I am facing one issue: I have one class (I call it GenericSetupTeardown) that extends GroovyTestCase and this is where I override setUp() and tearDown(). All my test classes then extend from my GenericSetupTeardown. When I run my test suite (class), it appears that setUp() gets run first for every test in that class, followed by the tests themselves! So if I have:

class SampleGroovyTCTestSuite extends GenericSetupTeardown {
   void test_FirstSample() {
      ...
   }
   void test_FirstSample() {
      ...
   }
}

I get two setUp() executed, followed by test_FirstSample(), followed by tearDown(), followed by test_FirstSample(), followed by tearDown().

Is this the correct behaviour, or am I just way off?

All the code is at sourceforge.net if it helps.

TIA for any advice.


View this message in context: GroovyTestCase runs all setUp()?
Sent from the groovy - user mailing list archive at Nabble.com.


Reply | Threaded
Open this post in threaded view
|

Re: GroovyTestCase runs all setUp()?

Wujek Srujek
You can check out TestNG - it has @BeforeMethod (setUp counterparts) as well as @BeforeClass, which gets run once before the first test method. There are also @AfterMethod and @AfterClass, and a few others. I am very happy that I made the switch to TestNG, try it. Groovy seems to be supporting it as well.

wujek

On Wed, Sep 28, 2011 at 6:38 PM, lam nguyen phuc <[hidden email]> wrote:
This is the expected behavior for every JUnit test case. The setUp() / tearDown() methods are called fixture methods and are executed before and after each test method, respectively. 


On Thu, Sep 29, 2011 at 12:33 AM, SiKing <[hidden email]> wrote:

Hi all.

I am a relative newb to the entire Java world, and I jumped into Groovy head first.

I am building up a test suite, and as my first attempt I did everything in JUnit4. Everything went fine.

I then discovered GroovyTestCase, and tried to redo everything to be more Groovy. I am facing one issue: I have one class (I call it GenericSetupTeardown) that extends GroovyTestCase and this is where I override setUp() and tearDown(). All my test classes then extend from my GenericSetupTeardown. When I run my test suite (class), it appears that setUp() gets run first for every test in that class, followed by the tests themselves! So if I have:

class SampleGroovyTCTestSuite extends GenericSetupTeardown {
   void test_FirstSample() {
      ...
   }
   void test_FirstSample() {
      ...
   }
}

I get two setUp() executed, followed by test_FirstSample(), followed by tearDown(), followed by test_FirstSample(), followed by tearDown().

Is this the correct behaviour, or am I just way off?

All the code is at sourceforge.net if it helps.

TIA for any advice.


View this message in context: GroovyTestCase runs all setUp()?
Sent from the groovy - user mailing list archive at Nabble.com.



Reply | Threaded
Open this post in threaded view
|

Re: GroovyTestCase runs all setUp()?

SiKing
In reply to this post by lam nguyen phuc
Maybe I was not clear:
I understand that setUp() is suppose to be run before each TEST. I get all the setUp() run at the start of the CLASS, followed by the test methods. This seems not right?