Scala 理解测试套件
我正在学习scalatest,有一个关于套房的问题。我想考一个Scala 理解测试套件,scala,testing,scalatest,Scala,Testing,Scalatest,我正在学习scalatest,有一个关于套房的问题。我想考一个 class ByteSource(val src: Array[Byte]) 从逻辑上讲,我将测试用例分为以下两部分: 空字节源 非空字节源 问题是这样将案例分成不同的套件是否正确: class ByteSourceTest extends FunSpec with Matchers{ describe("empty byte source operations"){ //... } de
class ByteSource(val src: Array[Byte])
从逻辑上讲,我将测试用例分为以下两部分:
class ByteSourceTest extends FunSpec with Matchers{
describe("empty byte source operations"){
//...
}
describe("non-empty byte source operations"){
//...
}
}
或者
FunSpec
不太适合这种情况?FunSpec
旨在提供最小的结构,因此这里没有硬性规定。自以为是结构的一个例子是WordSpec
。我的一个建议是,通过使用外部的描述(“ByteSource”)
来清楚地识别测试的主题:
测试对象的输出看起来像是自然语言中的规范:
A ByteSource
when empty
- should have size 0
- should produce NoSuchElementException when head is invoked
when non-empty
- should have size > 0
- should not produce NoSuchElementException when head is invoked
根据我的理解,没有此类义务。你选择你认为正确的,然后去做。在我看来,你的设计很好,我也会这么做。@dveim谢谢你的回复!我不确定这是否是
FunSpec
的某种惯用用法。。。
A ByteSource
when empty
- should have size 0
- should produce NoSuchElementException when head is invoked
when non-empty
- should have size > 0
- should not produce NoSuchElementException when head is invoked