Find file
Fetching contributors…
Cannot retrieve contributors at this time
69 lines (64 sloc) 2.78 KB
This file is a fully-functioning example test case. Try opening this file in Firefox, Safari,
or Internet Explorer to see what a running test looks like.
This file demonstrates the components involved in writing a simple test, such as:
* The necessary HTML to run a test (with the required <script> and <link rel="stylesheet"> tags),
* A "custom matcher" (i.e., a custom assertion) to make your tests more readable,
* And, a simple test with the necessary boiler-plate code to get you up and running.
Typically, these components are separated out into multiple files. To see what a more typical suite
of tests look like, look at the larger example in the examples/ directory.
<!-- These are all of the necessary javascript and css files required to run your tests -->
<script src="lib/jquery.js"></script>
<script src="lib/jquery.fn.js"></script>
<script src="lib/jquery.print.js"></script>
<script src="lib/hump.builder.js"></script>
<script src="lib/hump.matchers.js"></script>
<script src="lib/"></script>
<script src="lib/hump.behaviors.js"></script>
<link rel="stylesheet" href="lib/hump.css">
<script type="text/javascript">
// Here is the system under test (SUT)--that is, your application code that you would like
// to test.
function foo() {
return 2;
<script type="text/javascript">
// Here is a Custom Matcher. A custom matcher is a custom assertion,
// tailored to your application; these help to make your tests more readable.
Hump.Matchers["be_even"] = {
match: function(expected, actual) {
return actual % 2 == 0;
failure_message: function(expected, actual, not) {
return 'expected ' + $.print(actual) + (not ? ' not' : '') + ' to be even';
<script type="text/javascript">
// Here is a sample test. Note that all tests are wrapped in
// "Hump.Unit(function() { ... })".
Hump.Unit(function() {
// Tests are organized into 'describes' and 'its', following the style of RSpec.
describe("foo", function() {
it("returns 2", function() {
// 'equal' is one among many matchers provided with the Hump.Unit distribution. It
// is smart enough to compare arrays, objects, and primitives.
expect(foo()).to(equal, 2);
describe("numbers", function() {
// Here is a use of the custom matcher defined above.
it("either is or is not even", function() {