scalatest에서 Exception처리하는 예제이다. 


다음과 같은 포맷으로 개발한다. 


intercept[Exception] {

   메소드

}


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

@RunWith(classOf[JUnitRunner])
class AppSuite extends FunSuite {

test("test") {
checkParam("a")
}

test("null test") {
intercept[IllegalArgumentException] {
checkParam(null)
}
}

def checkParam(param: String): Int = param match {
case null => throw new IllegalArgumentException("None is illegal.")
case _ => 0
}

}


Posted by '김용환'
,