scala测试框架:scalatest
api文档:http://tool.oschina.net/apidocs/apidoc?api=scalatest-1.7.2
trait Assertions:http://tool.oschina.net/apidocs/apidoc?api=scalatest-1.7.2
traitFunSuite:http://tool.oschina.net/apidocs/apidoc?api=scalatest-1.7.2
请看代码片段一和二的区别:这里有很多规定写法。
代码片段一:是一个测试套,根据名字SetSuite识别。在IDEA中执行的时候,你可以选择执行整个测试套(包含2个用例),或者执行执行测试套的某个用例
package org.scalatest.examples.funsuite import org.scalatest.FunSuite class SetSuite extends FunSuite { test("An empty Set should have size 0") { assert(Set.empty.size === 0) } test("Invoking head on an empty Set should produce NoSuchElementException") { intercept[NoSuchElementException] { Set.empty.head } } }
代码片段二:是一个测试用例,根据名字SetTest识别。在IDEA执行的时候,只会执行一个测试用例setTest,测试用例的名字是固定写法
package org.scalatest.examples.funsuite import org.scalatest.FunSuite class SetTest extends FunSuite { test("setTest") { assert(Set.empty.size === 0) } test("setTest1") { intercept[NoSuchElementException] { Set.empty.head } } }
参考:
http://orchome.com/246
http://www.scalatest.org/quick_start
https://www.jianshu.com/p/ceabf3437dd7