In TestNg and Java, we can run multiple test cases using DataProvider, and this runs as separate tests, meaning execution of a test isn't stopped on failure. Is there an analogue for ScalaTest or Specs/Specs2?
ScalaTest is one of the most popular, complete and easy-to-use testing frameworks in the Scala ecosystem. Where ScalaTest differs from other testing tools is its ability to support a number of different testing styles such as XUnit and BDD out of the box.
When you mark a test class with a tag annotation, ScalaTest will mark each test defined in that class with that tag. Thus, marking the SetSpec in the above example with the @Ignore tag annotation means that both tests in the class will be ignored.
Regarding to the ScalaTest documentation: A test fixture is composed of the objects and other artifacts (files, sockets, database connections, etc.) tests use to do their work. When multiple tests need to work with the same fixtures, it is important to try and avoid duplicating the fixture code across those tests.
That concept is called "shared tests" in ScalaTest, because the same test code is being "shared" by multiple fixtures, where "fixtures" are the "data" in TestNG's DataProvider approach. There's a way to do this for each style trait in ScalaTest that expresses tests as functions. Here's an example for WordSpec:
http://www.scalatest.org/scaladoc-1.6.1/#org.scalatest.WordSpec@SharedTests
You can alternatively just use a for loop to register the same test code for different data points. This came up in an email discussion that's here:
http://groups.google.com/group/scalatest-users/browse_thread/thread/7337628407b48064#
The for loop code in that case looked like:
for (browser <- List("IE", "Chrome", "Firefox")) {
test(browser + ": test one") { driver =>
info("Testing using " + driver)
}
test(browser + ": test two") { driver =>
info("Testing using " + driver)
}
test(browser + ": test three") { driver =>
info("Testing using " + driver)
}
test(browser + ": test four") { driver =>
info("Testing using " + driver)
}
test(browser + ": test five") { driver =>
info("Testing using " + driver)
}
}
}
This actually registers 15 tests, five tests for each browser driver. This I believe is what you're after.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With