Mixing into the test cases

We can also mix traits into the individual test cases separately. This could allow us to apply customizations specific to those test cases only. The following is just a different representation of the preceding unit test:

package com.ivan.nikolov.compositionimport org.scalatest.{FlatSpec, Matchers}class TraitACaseScopeTest extends FlatSpec with Matchers {  "hello" should "greet properly." in new A {    hello() should equal("Hello, I am trait A!")  }  "pass" should "return the right string with the number." in new A {    pass(10) should equal("Trait A said: 'You passed 10.'")  }  it should "be correct also for negative values." in new A {    pass(-10) should equal("Trait A said: 'You passed -10.'")  }}

As you can see in the preceding ...

Get Scala Design Patterns - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.