Java Reference
In-Depth Information
Crunching Some Numbers
To demonstrate the TDD process, we'll have a go at creating a small library called “Num-
ber Cruncher” that will contain some functions that operate on numbers. The first function
we'll try to implement will be called factorsOf() . This will take a number as a para-
meter and return all the factors of that number as an array. [3]
To start, download the Jasmine library from GitHub. This is a zip file that needs to be ex-
tracted. Then open the directory called dist. This contains more zip files of all the recent
versions of Jasmine. Choose the latest version and extract it . These files should then be
copied into our project folder, called numberTest. The file structure should look similar to
the one in the screenshot in Figure 10.1 .
Figure 10.1. File structure
Delete all the files inside the spec and src folders as these are just useful examples that
are provided by Jasmine, and we're going to create our own. Inside the src folder, create a
blank file called numberCruncher.js; this is where our functions will go. Inside the spec
folder, create a blank file called numberSpec.js, which is where the tests will go.
The SpecRunner.html file is the file that runs the tests. The script tags will need changing
so that they refer to the correct files:
specRunner.html (excerpt)
<!-- include source files here... -->
<script type="text/javascript" src="src/
Search WWH ::

Custom Search