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