score:4

Accepted answer

Just override it with a lazy val:

trait A { val valueA: Int = 100500 }
trait B {
  val valueB: Int
  println(valueB)
}
class C extends A with B { lazy val valueB = valueA } 
new C 
// prints 100500

score:1

There are likely alternative ways to write the tests without having to use early initialisers (which are deprecated), for example the following might give some ideas

class FixturesSpec extends FlatSpec with Matchers {
  case class FixtureA(x: Int = 42)
  case class FixtureB(y: Int = -11)

  trait CommonFixture {
    val commonCaseValue: Int = 1
  }
  trait SpecialCaseFixture {
    val specialCaseValue: Int
  }

  "traits" should "be fixtures" in new SpecialCaseFixture with CommonFixture  {
    override val specialCaseValue = commonCaseValue
    specialCaseValue should be (1)
  }

  "case classes" should "be fixtures" in new FixtureA(FixtureB().y)  {
    x should be (-11)
  }
}

Related Query

More Query from same tag