O'Reilly logo

Scala Test-Driven Development by Gaurav Sood

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The Inside trait

ScalaTest contains an Inside trait. This feature, in turn, includes an inside construct. This construct is used to make assertions about the object graphs, which are nested. You can use pattern matching to do this.

Let's look at an example. Suppose, we have these case classes:

case class College(name:String, city:String, ranking:String) 
case class Student(fName:String, lName:String, rollNo:String) 
case class CollegeRecord(student:Student, college:College) 

Then, we can write specifications like this:

inside (cRec) { case CollegeRecord(student, college) => inside (student) { case Student(fName, lName, rollNo) => fName should be ("Johan") lName should be ("Sood") rollNo should be ("CTEC03812") } inside(college) { case College(name, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required