Return to Snippet

Revision: 65272
at November 14, 2013 03:07 by tedg


Initial Code
package scalaunittest

import org.scalatest.FlatSpec
import org.scalatest.matchers.ShouldMatchers

class ListFlatSpec extends FlatSpec with ShouldMatchers {
	val xs = List(1, 2, 3)
	
	"A List" should "have length as count of elements in it" in {
	    xs.length should be (3)
	}
	
	it should "contains elements passed in the factory method" in {
	    xs.contains(1) should be (true)
	    xs.contains(2) should be (true)
	    xs.contains(3) should be (true)
	}
	
	it should "throw IndexOutOfBounds exception when index is out of bounds" in {
	    evaluating {
	        xs(4)
	    } should produce [IndexOutOfBoundsException]
	}
}

Initial URL


Initial Description
A simple Scala unit test example using FlatSpec and ShouldMachers in scalatest

Initial Title
Scalatest example using FlatSpec and ShouldMatchers

Initial Tags


Initial Language
Scala