Search code examples
mspec

How to implement SpecFlow "Scenario Outline" in MSpec


My team have settled on MSpec for our BDD testing framework, which from their usage so far looks really good - but I'm struggling with the documentation/google for finding any implementation similar to SpecFlow's 'Scenario Outline'. I've shown an example of this below, but basically it allows you to write one 'test' and run it multiple times from a table (example) of inputs/expected outputs. I'll be embarrassed if answer turns out to be a LMGTFY but I've not been able to find anything myself. I don't want to say to the team it's not possible if I've just not found how to do it in MSpec (or understood MSpec properly). I wonder if this is why in some of the pro's/con's for MSpec I see references to the number of classes you can end up with listed as a negative.

Example of SpecFlow Scenario Outline

Scenario Outline: Successfully Convert Seconds to Minutes Table
    When I navigate to Seconds to Minutes Page
    And type seconds for <seconds>
    Then assert that <minutes> minutes are displayed as answer
Examples:
| seconds                       | minutes   | 
| 1 day, 1 hour, 1 second       | 1500      | 
| 5 days, 3 minutes             | 7203      | 
| 4 hours                       | 240       | 
| 180 seconds                   | 3         | 

From: https://gist.github.com/angelovstanton/615da65a8f821d7a43c92ef9e2fd0b01#file-energyandpowerconvertcalculator-feature


Solution

  • Short answer, this is current not supported by by mspec. We planned this several years back, but the contribution never made it back into master.

    If you want scenario outlines either use a different framework or create parameterized static methods in a helper class and call these from your context classes. Which will leave you with 1 class per scenario.