User guide   The Test Framework


Getting Started

Requirements and Installation

Before you install IeUnit you need the followings components on your computer:

After you have downloaded IeUnit setup file IeUnit_2_0_nnn.msi, you just double-click the file from the windows explorer to install it into any directory you choose. By default IeUnit is installed into the directory  c:\Program Files\IeUnit. During the installation a folder IeUnit will be created in Windows's Programs menu.  To test IeUnit installation you can run the IeUnit demo by selecting the menu Start>Programs>IeUnit>Run IeUnit Demo.

The Hello World Test Case

To demonstrate the use of IeUnit let us assume that we have a simple HTML document c:\temp\HelloWorld.html with the following source:

    <h2>Hello World!</h2>

Assume we want to create a script to test the following two features:

Notice that the complete source code for the Hello World test case is located in the directory %IEUNIT_HOME%\samples\HelloWorld.

We first open a prompt window by selecting the Windows menu Start>Programs>IeUnit>Create Test. This prompt window is just a normal command-line prompt window except it has adjusted some environment variables (like PATH and IEUNIT_HOME) to make IeUnit specific commands available. The working directory for this window is %IEUNIT_HOME%\workspace. From this working window we can now create a test case script HelloWorldTest.jst with notepad (or any editor we prefer) as follows:

1: function HelloWorldTest() {
2:    assimilate(this, new IeUnit());
4:    this.setUp = function() {
5:        this.openWindow("c:/temp/HelloWorld.html");
6:    };
7:    this.tearDown = function() {
8:       this.closeWindow();
9:   };
10:   this.testCheckText = function() {
11:       this.assertPageHasText("Hello World!");
12:   };
13:   this.testCheckStyle = function() {
14:    this.assertEquals("H1", this.findByText("Hello").tagName);
15:   };
16: }

The above code is pure JavaScript code except that it uses some special functions/classes made available by IeUnit framework. IeUnit uses the  name of the first function in a .jst file as the test case name, e.g. HelloWorld in above example. The test case name doesn't have to match the file name.  The above test script can be executed as follows:

C:\Program Files\IeUnit\workspace>StartTest.bat HelloWorldTest

Running case HelloWorldTest ...
RptTest: testCheckText: OK
RptTest: testCheckStyle: Failed: assertEquals failed. Expected: H1, got: H2
RptCase: HelloWorldTest: successes: 1, failures: 1
RptSuite: Successes: 1 Failures: 1 Time: 3.766sec

The above test output says that we have run a test case named HelloWorldTest with two tests named testCheckText and testCheckStyle. The second test has failed because of the mismatch of element type. The whole test suite has completed in 3.766 seconds.

More about the Test Script

Now let us take a closer look at the HellowWorldTest.jst script.  The first line, as mentioned above,  declares a JavaScript function whose name is used as the test case name. According JavaScript specification a function also defines a class which can be instanciated with the new operator. For instance, the statement new HellowWorldTest() will construct an object of the class HellowWorldTest. Line 2 to 15 in fact describe how to construct an object of  this class.

At line 2 the new HellowWorldTest object assimilates another objects of  class IeUnit. This statement makes many IeUnit specific functions and properties (e.g. openWindow(), assertEquals()) available for the new object. The concept assimilation is similar to the inheritance concept of the conventional object oriented programming. But assimilation works on the object level instead of class level. We will discuss about this in details latter.

Lines 4 to 6 defines the setup fixture for each test in this test case. Following the convention of xUnit framework the setUp method is called before running each test in this test case.  In our setUp method we just start the Internet Explorer browser and open the HelloWorld.html page.

Lines 7 to 9 define the tear-down fixture that cleans each test in this test case. In our case the tearDown method just closes the browser.

Lines 10 to 15 define two tests for this test case class. By the convention of IeUnit all methods whose names start with the prefix test are considered tests of the test case. The first test checks the text of the page whereas the second checks that the text "Hello" is located within a H1 HTML element.

Test Suites, Test Cases and Tests

Test suite, test case, and test are three main concepts of the xUnit test framework. IeUnit framework made some simplification to these concepts. The reason for the simplification is mainly for the sake of simplicity itself. 

These three concepts are realized in IeUnit as follows: a test case is realized by a JavaScript file with the file extension .jst and the file name is used as the test case name. A test suite is realized by a directory that contains one or more test case scripts. A test is realized by a method of a test case class whose name starts with the prefix test.


User guide   The Test Framework