Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Scala 理解测试套件_Scala_Testing_Scalatest - Fatal编程技术网

Scala 理解测试套件

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

我正在学习scalatest,有一个关于套房的问题。我想考一个

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