The first example is ScalaTest. ScalaTest provides many different usage patterns but the one I will show today is a Behaviour Driven Design test. It provides a DSL for declaring a test that is nearly english in syntax and if done correctly can be given to a non technical person to review. The ScalaTest BDD test style was inspired by the work done on Specs by Eric Torreborre. I will demonstrate that library in the next topic.
I want to reiterate that ScalaTest permits several different styles of test writing. NUnit, JUnit and BDD are the main styles. So anyone that is used to NUnit or JUnit should have no problem using ScalaTest but if you like the look of the BDD test specifications then you can migrate and slowly become accustomed to that style.
If you want to integrate with JUnit one easy way to add the @RunWith annotation for the class. See JUnitRunner for details:
- import org.scalatest.junit.JUnitRunner
- import org.junit.runner.RunWith
- @RunWith(classOf[JUnitRunner])
- class StackSpec extends WordSpec {
- ...
- }
Instructions to run example:
- Download ScalaTest: http://www.scalatest.org/download
- Extract archive. For example to /tmp/
- Run scala with the ScalaTest jar on classpath: scala -classpath /tmp/scalatest-1.0/scalatest-1.0.jar
- copy in code
This example is directly taken from the ScalaTest documentation. It tests a Stack implementation.
- scala> import org.scalatest.WordSpec
- import org.scalatest.WordSpec
- scala> import scala.collection.mutable.Stack
- import scala.collection.mutable.Stack
- scala>
- scala> class StackSpec extends WordSpec {
- |
- | "A Stack" should {
- |
- | "pop values in last-in-first-out order" in {
- | val stack = new Stack[Int]
- | stack.push(1)
- | stack.push(2)
- | assert(stack.pop() === 2)
- | assert(stack.pop() === 1)
- | }
- |
- | "throw NoSuchElementException if an empty stack is popped" in {
- | val emptyStack = new Stack[String]
- | intercept[NoSuchElementException] {
- | emptyStack.pop()
- | }
- | }
- | }
- | }
- defined class StackSpec
- scala> new StackSpec().execute()
- A Stack
- - should pop values in last-in-first-out order
- - should throw NoSuchElementException if an empty stack is popped
Merci pour logiciel et pour les informations
ReplyDeleteSi tu veux telecharger des logiciels gratuit free ICIIII
Et pour telecharger la meilleure version de logiciel test adsl