JsUnit: Part 1
Writing and manually running
JavaScript Tests with the XUnit
framework for in-browser JavaScript
What is an XUnit framework?
•
A standardized set of language-independent concepts
and constructs for writing and running unit tests
•
There is an XUnit framework for virtually every language
•
Examples are JUnit for Java, CppUnit for C++, PHPUnit
for PHP, UTPL/SQL for Oracle SQL
•
Traditionally open-source
•
All support certain constructs:
–
TestCase and TestSuite are well-defined entities
–
The assertion syntax follows rough standards, e.g.
assertEquals(comment, expected, actual)
•
All provide a TestRunner program to run tests
•
Listed at http://xprogramming.com/software.htm
JsUnit: background
•
The XUnit framework for JavaScript
•
www.jsunit.net
•
Open source (hosted on Sourceforge)
•
Preserves the standards of a typical XUnit
framework
•
Written in 100% JavaScript
•
Runs on “most” browser/platform combinations
•
Development began in early 2001
•
~10,000 downloads and ~1000 members of the
news group
JsUnit: conforming to XUnit
•
Unit tests in JsUnit are called Test Functions
•
Test Functions live in an HTML page called a Test Page
•
A Test Page is any HTML page that has a JavaScript
“include” of jsUnitCore.js
•
jsUnitCore.js provides the assertion functions of
JsUnit, e.g. assertEquals(comment, arg1, arg2)
•
JsUnit supports setUp() and tearDown()
•
A Test Suite Page declares a suite() function that
returns a JsUnitTestSuite for grouping Test Pages
•
The JsUnit testRunner.html page runs Test Pages
•
The TestRunner HTML page can be run from a file
server or a web server