我是靠谱客的博主 冷傲奇迹,这篇文章主要介绍scala代码之测试类AnyFunSuite,现在分享给大家,希望可以做个参考。

代码测试是开发人员的日常工作,java代码一般用junit框架,scala代码当然也可以用junit。有没有不用junit,用更简便的方式来测试代码呢?
当然有,本章介绍scala的测试类AnyFunSuite
先看该类如何使用:

复制代码
1
2
3
4
5
6
1.测试类继承AnyFunSuite 2.test(testName:String) { 测试代码 } 3.右键运行

测试代码如下:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import org.scalatest.funsuite.AnyFunSuite class TestAnyFunSuite extends AnyFunSuite{ val str = "hello" val add = (a: Int, b: Int) => a + b val sub = (a: Int, b: Int) => a - b def calculate(a: Int, b: Int, oper:(Int, Int) => Int) : Int = { oper(a, b) } //测试方法1 test("test1") { println(str) } //测试方法2 test("test2") { println(calculate(1, 2, add)) } }

用该测试类还是比较方便的,不需要额外引入junit,小伙伴们用起来吧!

最后

以上就是冷傲奇迹最近收集整理的关于scala代码之测试类AnyFunSuite的全部内容,更多相关scala代码之测试类AnyFunSuite内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(71)

评论列表共有 0 条评论

立即
投稿
返回
顶部