• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

scala代码:测试类AnyFunSuite

武飞扬头像
黄金刀
帮助1

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

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

测试代码如下:

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,小伙伴们用起来吧!

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhgkhgah
系列文章
更多 icon
同类精品
更多 icon
继续加载