Integrating JsUnit with NUnit using WatiN

We have 500+ JsUnit tests on my current project. These tests are a very valuable asset to the team. Their true value is not realized unless they are integrated into our automated build process.

[Test]public void RunJSUnitTests(){    string testDirectory = ConfigurationManager.AppSettings["JsTestDir"];    ITestFileReader reader =        new ExcludeTestFileReader("jsunit",        new SuffixTestFileReader("tests.htm",        new TestFileReader(testDirectory)));    Assert.IsTrue(new JsUnitTestRunner(reader).Run());}

This NUnit test runs all of our JsUnit tests.ITestFileReader is the most crucial part of the above code. ITestFileReader is the type responsible for feeding JsUnit test files to the JsUnitTestRunner. There are currently three types of ITestFileReaders:TestFileReader

Returns each file in the directory, including subdirectories, with each call to GetNextTestFile. Expects the name of a directory as its parameter.


Decorator for a ITestFileReader that ensures all test files end with a specific postfix. Expects a sufÅfix string and a ITestFileReader.


Decorator for a ITestFileReader that ensure only files that do not match the exclude string are returned from the GetNextTestFile.

When new JsUnitTestRunner(reader).Run() is executed a new JsUnit suite is generated and saved to all_tests.html. WatiN is then used to execute the suite in JsUnit’s test runner.Add the following to your App.config so JsUnitTestRunner can find your JsUnit installation. InstallDir is the directory where you have unzipped JsUnit.

<configSections>    <section name="JSUnit" type="System.Configuration.NameValueSectionHandler" /></configSections><JSUnit>    <add key="InstallDir" value="c:\Projects\jsunit\" /></JSUnit>

If you want more information, please ask and/or look through the unit tests used to create the JsUnitTestRunner. All comments and suggestions are welcome. All of the source code can be found in my svn repository.


4 Responses

  1. Looks pretty nice!

  2. Hey Adam, I really like the approach you took with integrating JsUnit using WatiN. I’m doing something very similar. I’m writing all my tests as standalone JS files which get included into a dynamic HTML page. I’m also integrating an ASHX handler to report JsUnit error descriptions in NUnit. I would like to use some of what you have done.

    I guess my question is, what’s the license for your code? (

  3. It is in the public domain. You may do with it as you wish.

  4. Cho đoạn javascript kiểm tra so sánh hai ngày :

    function iesvn_CompareDate(fromDate, toDate) {
    if ((fromDate == “”) || (toDate == “”)) {
    return null;
    var arrFromDate = fromDate.split(“/”);
    var arrToDate = toDate.split(“/”);
    if (arrFromDate.length != 3 || arrToDate.length != 3) {

    return null;

    var d1 = iesvn_GetDateFromFormat(fromDate, “d/M/yyyy”);
    var d2 = iesvn_GetDateFromFormat(toDate, “d/M/yyyy”);
    if (d1 == 0 || d2 == 0) {
    return null;
    } else {
    if (d1 > d2) {
    return 1;
    } else {
    if (d1 == d2) {
    return 0;
    return -1;
    làm ơn chỉ cho em cách test đoạn Javascript trên. ngày hiện tiện lớn hơn ngày quá khứ; ngày hiện tại nhỏ hơn ngày o tương lai.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: