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, ...

Get Scala Test-Driven Development 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.