- 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.
- Add one more test to the same file:
src/test/scala/com/packt/courseware/l1/ExampleSpec.scala in 2-project
- We write one
trivial
test, which asserts thefalse
expression:test("trivial") { assert(false) }
- Run the test and look at error reporting.
- Invert the expression in assert so that the test passes:
test("trivial") { assert(true) }
- Run the
sbt
test again to ensure that all of the tests pass.
推薦閱讀
- Application Development with Qt Creator(Second Edition)
- C++黑客編程揭秘與防范
- 物聯網識別技術
- SEO 20日
- 計算機網絡與數據通信
- Learning Karaf Cellar
- Hands-On Full Stack Development with Spring Boot 2 and React(Second Edition)
- Windows Server 2012 Hyper-V虛擬化管理實踐
- 網絡AI+:2030后的未來網絡
- 網管第一課:網絡操作系統與配置管理
- 端到端QoS網絡設計
- 全聯網標識服務
- SEO攻略:搜索引擎優化策略與實戰案例詳解
- 區塊鏈技術與應用:打造分布式商業新生態
- 物聯網導論