1.断言

assert(conditon)将在条件不成立的时候,抛出assertionError

assert(conditon,explanation)讲在条件不成立的时候,抛出explanation作为说明

package com.scala.first

/**
* Created by common on 17-4-19.
*/
object Assert { def main(args: Array[String]): Unit = {
val a = new Assert()
a.above1(0) } } class Assert {
val value = 1 def above(that: Int): Unit = {
val thatVal = that
val thisVal = this.value
//如果条件不满足,Exception in thread "main" java.lang.AssertionError: assertion failed
assert(thatVal == thisVal)
} //另一种断言
//如果条件不满足,Exception in thread "main" java.lang.AssertionError: assertion failed
def above1(that: Int): Unit = {
{
val thatVal = that
val thisVal = this.value
} ensuring(that == this.value) }
}

2.单元测试

Scala中提供了多种单元测试的方法,比如ScalaTest

ScalaTest提供了多种单元测试的方法,最简单的就是创建org.scalatest.suite类,并在这些类中定义测试方法

如果cmd+shift+T的快捷键无效的话,在需要测试的类上右键,Go to Test,创建一个测试类

最新文章

  1. Excel——使用OFFSET、MATCH、COUNTA实现二级菜单
  2. CSS3动画快速实现
  3. Value cannot be null or empty. 参数名: contentPath
  4. IOS , plist 配置项说明
  5. vs2012无法启动已配置的开发Web服务器
  6. codeforces399D
  7. html5 canvas 鼠标绘制
  8. SQL SERVER调优常用方法
  9. BestCoder Round #71 (div.2) (hdu 5621)
  10. [未完成]关于SQL语句的总结
  11. 初探react
  12. 老李推荐:第8章6节《MonkeyRunner源码剖析》MonkeyRunner启动运行过程-启动Monkey 4
  13. Kaggle Challenge简要介绍
  14. tomcat加入系统服务+开机自启
  15. VS2013创建Windows服务 || VS2015+Windows服务简易教程
  16. 探索SQL Server元数据(一)
  17. javascript之reduce()方法的使用
  18. Object类的wait方法带参数和notifyAll方法
  19. CentOS切换为iptables防火墙并进行相关配置
  20. 舞蹈链(DLX)

热门文章

  1. [洛谷U40581]树上统计treecnt
  2. db2 codepage
  3. 第二章 flex输入输出
  4. Python:内置函数
  5. 集合(5)—Map之HashMap()
  6. 各种组件的js 获取值 / js动态赋值
  7. 谈一下Docker与Kubernetes集群的日志和日志管理
  8. SpringMVC拦截器详解
  9. libnids使用 (转)
  10. 版本控制git(三)-git分支