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
}
}
'scala' 카테고리의 다른 글
[spark2] partitonBy, HashPartitioner, RangePartitioner 예제 (0) | 2017.08.07 |
---|---|
[spark2] cache()와 persist()의 차이 (0) | 2017.08.01 |
[scala] scalablitz (0) | 2017.07.27 |
[scala] 병렬 콜렉션 (par collection) (0) | 2017.07.24 |
[scala] foldLeft, fodRight, reduceLeft, reduceRight, scanLeft, scanRight 함수 예제 (0) | 2017.07.24 |