Best practice for constructing tests

Oct 28, 2010 at 5:14 PM


Just getting to grips with StoryQ and am wondering if I’m doing the right thing.

Here’s an NUnit test (see below) to verify that when an trading quote tile (widget) is notified that the market is closed it stops receiving quotes. The use case itself is not important. I have some observations / questions.

tileViewModel is a member of the test class and the action methods operate on it transparently.

I’ve experimented with passing an explicit subject to each method but the code looks messy and so does the report.

Extension methods report OK but the code still looks a bit odd.

What’s best practice?


You will see I create a tileViewModel outside the scenario. Should I have an action that Given() invokes to setup the subject?


How do I handle events that will fire later? For example, in the test below, when the tile unsubscribes, it will fire an event and I want to check that the event fires?


Any other pointers for this BDD newbie would be very helpful.


Also, what about test naming? My current standard is:


I hit on this before using StoryQ. Now tests are expressed in Gherkin, what to do about test names?






       public void Test_MarketClosing_TileStopped_TileRemainsStopped()


           this.tileViewModel = this.CreateQuoteTileVmOne();




               .Given(TheDetailedMarketStatusIs_, MarketStatusCode.Open)

               .And(TheTileMarketStatusIs_, MarketStatus.Open)




               .When(TheDetailedMarketStatusChangesTo_, MarketStatusCode.Closed)


               .Then(TheTileMarketStatusIs_, MarketStatus.Closed)