官术网_书友最值得收藏!

Inside Tests

Now let's look at a simple test:

package com.packt.courseware.l1
import org.scalatest.FunSuite

class ExampleSpec extends FunSuite {

  test("example test  should pass") {
     assert(1==1)
  }

}

Here, we define a class which is inherited from scalatest FunSuite.

The test expression is called. When the FunSuite class is initialized and added to a set of tests, the test with name example test should pass and assert an expression as an argument. For now, this looks like magic, but we will show you how to build such DSLs in the next chapter.

Let's run our test with the help of sbt:

sbt test

This command will run all tests and evaluate the test expression.

Now, we'll add another test.

  1. Add one more test to the same file: src/test/scala/com/packt/courseware/l1/ExampleSpec.scala in 2-project
  2. We write one trivial test, which asserts the false expression:
          test("trivial")  {
                assert(false)
           }
  3. Run the test and look at error reporting.
  4. Invert the expression in assert so that the test passes:
          test("trivial")  {
                assert(true)
           }
  5. Run the sbt test again to ensure that all of the tests pass.
主站蜘蛛池模板: 建平县| 柘荣县| 樟树市| 吉木乃县| 南开区| 宝丰县| 永嘉县| 赫章县| 馆陶县| 神木县| 柞水县| 高淳县| 镇康县| 通许县| 牙克石市| 海口市| 乌兰浩特市| 延长县| 通化县| 炉霍县| 湘潭县| 堆龙德庆县| 安庆市| 禄丰县| 杂多县| 屏南县| 益阳市| 苍梧县| 甘谷县| 柞水县| 哈密市| 承德县| 兖州市| 精河县| 新巴尔虎左旗| 调兵山市| 定兴县| 靖江市| 莱阳市| 尼勒克县| 沾益县|