Return to Snippet

Revision: 65274
at November 14, 2013 03:18 by tedg


Initial Code
package scalaunittest

import org.scalatest.FunSuite
import org.scalatest.junit.JUnitRunner
import org.junit.runner.RunWith

@RunWith(classOf[JUnitRunner])	// Run As | JUnit Test
class ListFunSuite extends FunSuite {
	/*
	 * This is a test. The test method takes two arguments.
	 * The first argument is the test name or description
	 * The second argument is a block of code to execute, that is, the test body.
	 */
    test("list length") {
	    val ls = List(2, 3, 4)
	    
	    // This is the way to expect an exception.
	    intercept[IndexOutOfBoundsException] {ls(5)}	    
	}
}

Initial URL

                                

Initial Description
A simple Scala unit test example using FunSuite in scalatest. The test expects an exception.

Initial Title
Scalatest example using FunSuite, expecting exception

Initial Tags

                                

Initial Language
Scala