O'Reilly logo

Cocoa Programming for OS X: The Big Nerd Ranch Guide by Aaron Hillegass, Adam Preble, Nate Chandler

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

A Note on Literals in Testing

When writing tests, it can often at first seem more convenient to use literals (such as "tomato" and 54). For example, rather than creating separate variables for each of the arguments, it may at first seem easier to write the following:

l​e​t​ ​c​o​u​r​s​e​ ​=​ ​C​o​u​r​s​e​(​t​i​t​l​e​:​ ​"​N​a​m​e​"​,​
 ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​u​r​l​:​ ​N​S​U​R​L​(​s​t​r​i​n​g​:​ ​"​h​t​t​p​:​/​/​b​i​g​n​e​r​d​r​a​n​c​h​.​c​o​m​/​"​)​!​,​
 ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​n​e​x​t​S​t​a​r​t​D​a​t​e​:​ ​N​S​D​a​t​e​(​)​)​

The problem with this approach, of course, is that you have to use another literal later on when you want to use the value again:

X​C​T​A​s​s​e​r​t​E​q​u​a​l​(​c​o​u​r​s​e​.​t​i​t​l​e​,​ ...

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