October 2016
Intermediate to advanced
198 pages
3h 52m
English
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, ...Read now
Unlock full access