Search code examples
scalacucumberoutline

How to implement scenario outlines in scala


We are currently implementing some acceptance tests using Scala.

In cuke, there is a notion of scenario outline.

Does anyone know how to implement this using the FeatureSpec in Scala?

Thanks in advance.


Solution

  • I think scenario outline is a cucumber feature, and I'm not sure you should necessarily expect find parity in existing Scala testing libraries.

    That being said, I've used cucumber-scala and used scenario outlines in some of my projects, here are the dependencies i used (check for newer versions, and please don't assume this is the end-all way to do this):

    "com.novocode" % "junit-interface" % "0.11-RC1" % "test",
    "info.cukes" % "cucumber-core" % "1.1.8" % "test",
    "info.cukes" % "cucumber-junit" % "1.1.8" % "test",
    "info.cukes" %% "cucumber-scala" % "1.1.8" % "test",
    "org.mockito" % "mockito-core" % "1.9.5" % "test"
    

    And here is an example of what my runner looked like:

    import cucumber.api.junit.Cucumber
    import org.junit.runner.RunWith
    
    @RunWith(classOf[Cucumber])
    class CucumberRunner {}
    

    Here is an example of a given clause loading an outline table:

    Given("""^some data$""") { (t: DataTable) =>
      val input = t.asMaps(classOf[String], classOf[String])
      // use table data...
    }
    

    And i took the particulars out, but that was dealing with a gerkin file like this (stored in main/test/resources in the same package):

    Background:
      Given some data
        |  a |    b |     c |         d |
        |  1 |    a |   0.0 | s030d1h60 | 
        |  2 |    a |   1.0 | s030d1h60 | 
        |  3 |    a |   2.0 | s030d1h60 |     
      And some setup parameter "q"
      When the input is processed by the mock item
    
    Scenario: The input can be validated
      Then the input will be marked as valid
    
    Scenario: The input will be transformed
      Then the input will be trasformed into "abcdef"
    

    I know this isn't specifically what you wanted, but it's something that worked for me as a first attempt at doing some BDD-like stuff in Scala. Hope it helps.