Note
Safari Books Online is an on-demand digital library that delivers expert content in both book and video form from the worlds leading authors in technology and business.
Technology professionals, software developers, web designers, and business and creative professionals use Safari Books Online as their primary resource for research, problem solving, learning, and certification training.
Safari Books Online offers a range of product mixes and pricing programs for organizations, government agencies, and individuals. Subscribers have access to thousands of books, training videos, and prepublication manuscripts in one fully searchable database from publishers like OReilly Media, Prentice Hall Professional, Addison-Wesley Professional, Microsoft Press, Sams, Que, Peachpit Press, Focal Press, Cisco Press, John Wiley & Sons, Syngress, Morgan Kaufmann, IBM Redbooks, Packt, Adobe Press, FT Press, Apress, Manning, New Riders, McGraw-Hill, Jones & Bartlett, Course Technology, and dozens more. For more information about Safari Books Online, please visit us online.
How to Contact Us
Please address comments and questions concerning this book to the publisher:
OReilly Media, Inc. |
1005 Gravenstein Highway North |
Sebastopol, CA 95472 |
800-998-9938 (in the United States or Canada) |
707-829-0515 (international or local) |
707-829-0104 (fax) |
We have a web page for this book, where we list errata, examples, and any additional information. You can access this page at http://oreil.ly/JS_Jasmine.
To comment or ask technical questions about this book, send email to .
For more information about our books, courses, conferences, and news, see our website at http://www.oreilly.com.
Find us on Facebook: http://facebook.com/oreilly
Follow us on Twitter: http://twitter.com/oreillymedia
Watch us on YouTube: http://www.youtube.com/oreillymedia
Acknowledgments
Thanks to RockMelt for asking me to learn Jasmine.
Thanks to Pivotal Labs for creating Jasmine.
Thanks to my parents for their constant support.
Chapter 1. Intro to Testing
What Is Software Testing?
In short, you can test software against a specification.
Lets say youre writing a simple calculator that just does addition. Before you even start, think about how it should behave. It should be able to add positive integers. It should be able to add negative integers. It should be able to add decimal numbers, not just integers. You can think of many different ways that your calculator needs to work.
Before youve written any of the code, you know how you want it to behave. You have a specification for its behavior.
You can write these specifications in code. Youd say, OK, it should work this way. Youd make tests that added 1 and 1, 2 and 2, 1 and 5, 1.2 and 6.8, 0 and 0, and so on. When you run these tests, youll either get a success (it works according to the specification) or a failure (it doesnt). If you ran all of your tests and saw success for each, then you can be pretty sure that your calculator works. If you ran these tests and saw some failures, then you know that your calculator doesnt work.
Thats software testing in a nutshell. Youre testing your code against a specification. There are many tools (Jasmine among them) that help you automate these software tests.
Its important to know that its difficult (and often impossible) to write tests for every case. In the calculator example, there are an infinite number of possible combinations. When testing, you should try to cover every reasonable case by testing a number of different groups (integers, negative numbers, mixes of the two, etc.). You should also identify boundary conditions (zeroes, for example) and edge cases, testing as many different scenarios as possible.