setup/teardown

3 views
Skip to first unread message

Eric Lefevre-Ardant

unread,
Dec 3, 2010, 12:08:05 PM12/3/10
to narrati...@googlegroups.com
Hi,

I am hitting a problem with Narrative.

You see, we use to have a parent test class that would basically provide the same service that an actor do. So, I've now created actors that have those capabilities, and my test classes do not inherit from this parent class anymore.

One problem I have is the setting up of the tool and, especially the tear down.
You see, an actor needs to start things on the tool (the grid in my case). I can solve this by doing so at the first action. Not great, but it works for now as I only have one such action.

However, I also need to shutdown the grid, so that it is cleaned up for the next test. And I do not see a clean way of doing so.

One option I see is implement an @After method in my test class that would delegate to a tearDown() method in the actor. But there is no reason for this actor to be the one used in the last test (I have 2 actors in this test class), so I'd have to test for which actor has been used. Pretty ugly.

It seems to me that one idea in Narrative is that the environment ("tool") is attached to the actor. That breaks the setUp() / tearDown() paradigm we are used to under JUnit.

Thoughts?

Thanks,

Eric

Felix Dilke

unread,
Dec 3, 2010, 12:25:29 PM12/3/10
to narrati...@googlegroups.com

Hi Eric,

 

One thing you could do that might help:

 

In setup:

   Create the tool

   Create the actor around it

 

In teardown:

  Delete the actor

  Delete the tool

 

An additional optimization might be to start up / take down the grid in Before/AfterClass methods.

 

Felix

Samir Talwar

unread,
Dec 3, 2010, 12:30:16 PM12/3/10
to narrati...@googlegroups.com
If the setup and teardown are different for each test method, why not just call them in the methods themselves?

@Test public void checksThatSomethingWorks() {
actor.setUp();

Given.the(actor).was_able_to(do_something());

When.the(actor).attempts_to_(do_the_thing());

Then.the(actor).expects_that(the_thing(), is(working()));

actor.tearDown();

Eric Lefevre-Ardant

unread,
Dec 6, 2010, 5:00:56 AM12/6/10
to narrati...@googlegroups.com
Yep, that works. Thanks!

That said, I thought it was the actor that was supposed to instantiate the tool? At least, that's the feeling I had when reading the samples.

Eric

Eric Lefevre-Ardant

unread,
Dec 6, 2010, 5:03:21 AM12/6/10
to narrati...@googlegroups.com
Yes, I see how that would be necessary in some cases. However, it is probably a good idea to aim at having similar setups for all tests, if possible. I rather like the readability of just having Given/When/Then.

Thanks

Eric
Reply all
Reply to author
Forward
0 new messages