[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Per suite unit test setup and teardown

Peter Hickman

8/28/2008 11:38:00 AM

I am putting some tests together that need to access an external service
which I can use setup() and teardown() to control. The problem is that
these methods are run before and after each test, this slows things down
quite a bit. Ideally there would be one setup before all the tests are
run and one teardown at the end. Nunit has this functionality and I'm
sure I've seen it in other frameworks.

Is there a way to get until test to do this or will I have to end up
putting all my tests in a single test method?


7 Answers

Ron Fox

8/29/2008 2:23:00 PM

0

Peter Hickman wrote:
> I am putting some tests together that need to access an external service
> which I can use setup() and teardown() to control. The problem is that
> these methods are run before and after each test, this slows things down
> quite a bit. Ideally there would be one setup before all the tests are
> run and one teardown at the end. Nunit has this functionality and I'm
> sure I've seen it in other frameworks.
>
> Is there a way to get until test to do this or will I have to end up
> putting all my tests in a single test method?
>
>
Prior to all test executions.. you could put the setup at the outer
level of the script file.

--
Ron Fox
NSCL
Michigan State University
East Lansing, MI 48824-1321

Peter Hickman

8/29/2008 2:47:00 PM

0

Ron Fox wrote:
> Peter Hickman wrote:
>> I am putting some tests together that need to access an external
>> service which I can use setup() and teardown() to control. The
>> problem is that these methods are run before and after each test,
>> this slows things down quite a bit. Ideally there would be one setup
>> before all the tests are run and one teardown at the end. Nunit has
>> this functionality and I'm sure I've seen it in other frameworks.
>>
>> Is there a way to get until test to do this or will I have to end up
>> putting all my tests in a single test method?
>>
>>
> Prior to all test executions.. you could put the setup at the outer
> level of the script file.
>

Putting the global setup code outside the class does work but there is
no way to get the global teardown to work. Even putting it in an END
block (a horrible Perlism) doesn't work.

Then you come to test suites, which results in all the global startup
code being run before any of the tests.

I think I will have to look into the code for unit test, how hard can it
be?

Pit Capitain

9/9/2008 10:06:00 AM

0

2008/8/29 Peter Hickman <peter@semantico.com>:
> Putting the global setup code outside the class does work but there is no
> way to get the global teardown to work. Even putting it in an END block (a
> horrible Perlism) doesn't work.

Peter, you have to double the horror to get what you want:

END {
END {
puts "this is run after the tests"
}
}

I think I learned this trick from Ara.

Regards,
Pit

Daniel Berger

9/9/2008 2:19:00 PM

0

On Aug 28, 5:38 am, Peter Hickman <pe...@semantico.com> wrote:
> I am putting some tests together that need to access an external service
> which I can use setup() and teardown() to control. The problem is that
> these methods are run before and after each test, this slows things down
> quite a bit. Ideally there would be one setup before all the tests are
> run and one teardown at the end. Nunit has this functionality and I'm
> sure I've seen it in other frameworks.
>
> Is there a way to get until test to do this or will I have to end up
> putting all my tests in a single test method?

They were added to test-unit 2.0:

http://rubyforge.org/forum/forum.php?foru...

gem install test-unit

Regards,

Dan

Pit Capitain

9/9/2008 6:43:00 PM

0

2008/9/9 Daniel Berger <djberg96@gmail.com>:
> They were added to test-unit 2.0:

Thank you for the hint, Daniel. I missed the new release.

Regards,
Pit

ruud grosmann

9/10/2008 10:15:00 AM

0

>
> Peter, you have to double the horror to get what you want:
>
> END {
> END {
> puts "this is run after the tests"
> }
> }
>
> I think I learned this trick from Ara.


Why is a single END not enough? What is happening here?

RG

Peter Hickman

9/10/2008 10:23:00 AM

0

Daniel Berger wrote:
> They were added to test-unit 2.0:
>
> http://rubyforge.org/forum/forum.php?foru...
>
> gem install test-unit
>
> Regards,
>
> Dan
>
>
>


Oh thanks for that. Will get downloading asap.