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

  • Professional Scala
  • Mads Hartmann Ruslan Shevchenko
  • 177字
  • 2021-07-23 17:24:24

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.
主站蜘蛛池模板: 江阴市| 南乐县| 元氏县| 扬州市| 南木林县| 高密市| 徐水县| 麻栗坡县| 漳州市| 监利县| 沙河市| 淮阳县| 陈巴尔虎旗| 二手房| 大余县| 平邑县| 汝南县| 遂宁市| 子长县| 昌吉市| 稷山县| 珲春市| 洛川县| 许昌市| 潜江市| 临澧县| 贺兰县| 巴彦淖尔市| 抚远县| 新野县| 清远市| 丹江口市| 兴化市| 牙克石市| 集安市| 富宁县| 丹阳市| 尼玛县| 鄂托克旗| 迁西县| 龙川县|