上QQ阅读APP看书,第一时间看更新
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.