TIP JSUnitContrib is not installed on Foswiki.org.

JSUnitContrib

alert According to http://www.jsunit.net/, JSUnit is no longer maintained. Try a different JavaScript unit testing framework, such as js-test-driver.

JSUnit JavaScript unit testing framework.

Usage

After installing, include the core js file with:
<script language="javascript" src="%PUBURL%/%SYSTEMWEB%/JSUnitContrib/app/jsUnitCore.js"></script>

Example

Adapted example from the site:

Suppose we want to write a test for a function called multiplyAndAddFive(value1, value2) which multiplies value1 and value2 together, adds five, and returns the result. Also suppose that this function lives in a file called sample_script_to_test. Assume that if non-numeric values are passed in, the function should return null. A suitable Test Page would look like the following:

<html>
<head>
<title>Test Page for multiplyAndAddFive(value1, value2)</title>
<script language="javascript" src="%PUBURL%/%SYSTEMWEB%/JSUnitContrib/app/jsUnitCore.js"></script>
<script language="javascript" src="%PUBURL%/%SYSTEMWEB%/JSUnitContrib/sample_script_to_test.js"></script>
</head>
<body>
<script language="javascript">
    function testWithValidArgs() {
        assertEquals("2 times 3 plus 5 is 11", 11, multiplyAndAddFive(2, 3));
        assertEquals("Should work with negative numbers", -15, multiplyAndAddFive(-4, 5));
    }
    function testWithInvalidArgs() {
        assertNull("A null argument should result in null", multiplyAndAddFive(2, null));
        assertNull("A string argument should result in null", multiplyAndAddFive(2, "a string"));
    }
    function testStrictReturnType() {
        assertNotEquals("Should return a number, not a string", "11", multiplyAndAddFive(2, 3));
    }
    function testWithUndefinedValue() {
        assertNull("An undefined argument should result in null", multiplyAndAddFive(2, JSUNIT_UNDEFINED_VALUE));
    }
</script>
*[[%PUBURL%/%SYSTEMWEB%/JSUnitContrib/testRunner.html?testpage=%SCRIPTURL{"view"}%/%SYSTEMWEB%/JSUnitContrib][Run test]]*
</body>
</html>

If installed this will result in:

Run test

Documentation

See: http://www.jsunit.net/documentation/

Settings

  • Set SHORTDESCRIPTION = JSUnit JavaScript unit testing framework
  • Set STUB = %$STUB%

Installation Instructions

  • Download the ZIP file from the Extensions web (see below)
  • Unzip JSUnitContrib.zip in your ($TWIKI_ROOT) directory. Content:
    File: Description:
    data/System/JSUnitContrib.txt  
    lib/Foswiki/Contrib/JSUnitContrib.pm  
    pub/System/JSUnitContrib/sample_script_to_test.js  
    pub/System/JSUnitContrib/app/css/jsUnitStyle.css  
    pub/System/JSUnitContrib/app/css/readme  
    pub/System/JSUnitContrib/app/emptyPage.html  
    pub/System/JSUnitContrib/app/jsUnitCore.js  
    pub/System/JSUnitContrib/app/jsUnitMockTimeout.js  
    pub/System/JSUnitContrib/app/jsUnitTestManager.js  
    pub/System/JSUnitContrib/app/jsUnitTestSuite.js  
    pub/System/JSUnitContrib/app/jsUnitTracer.js  
    pub/System/JSUnitContrib/app/jsUnitVersionCheck.js  
    pub/System/JSUnitContrib/app/main-counts-errors.html  
    pub/System/JSUnitContrib/app/main-counts-failures.html  
    pub/System/JSUnitContrib/app/main-counts-runs.html  
    pub/System/JSUnitContrib/app/main-counts.html  
    pub/System/JSUnitContrib/app/main-data.html  
    pub/System/JSUnitContrib/app/main-errors.html  
    pub/System/JSUnitContrib/app/main-frame.html  
    pub/System/JSUnitContrib/app/main-loader.html  
    pub/System/JSUnitContrib/app/main-progress.html  
    pub/System/JSUnitContrib/app/main-results.html  
    pub/System/JSUnitContrib/app/main-status.html  
    pub/System/JSUnitContrib/app/testContainer.html  
    pub/System/JSUnitContrib/app/testContainerController.html  
    pub/System/JSUnitContrib/app/xbDebug.js  
    pub/System/JSUnitContrib/bin/mac/readme.txt  
    pub/System/JSUnitContrib/bin/mac/start-firefox.scpt  
    pub/System/JSUnitContrib/bin/mac/start-firefox.sh  
    pub/System/JSUnitContrib/bin/mac/start-safari.scpt  
    pub/System/JSUnitContrib/bin/mac/start-safari.sh  
    pub/System/JSUnitContrib/bin/mac/stop-firefox.scpt  
    pub/System/JSUnitContrib/bin/mac/stop-firefox.sh  
    pub/System/JSUnitContrib/bin/mac/stop-safari.scpt  
    pub/System/JSUnitContrib/bin/mac/stop-safari.sh  
    pub/System/JSUnitContrib/bin/unix/start-firefox.sh  
    pub/System/JSUnitContrib/bin/unix/stop-firefox.sh  
    pub/System/JSUnitContrib/build.xml  
    pub/System/JSUnitContrib/changelog.txt  
    pub/System/JSUnitContrib/css/jsUnitStyle.css  
    pub/System/JSUnitContrib/images/green.gif  
    pub/System/JSUnitContrib/images/logo_jsunit.gif  
    pub/System/JSUnitContrib/images/powerby-transparent.gif  
    pub/System/JSUnitContrib/images/red.gif  
    pub/System/JSUnitContrib/index.jsp  
    pub/System/JSUnitContrib/jsunit.properties.sample  
    pub/System/JSUnitContrib/licenses/gpl-2.txt  
    pub/System/JSUnitContrib/licenses/index.html  
    pub/System/JSUnitContrib/licenses/JDOM_license.txt  
    pub/System/JSUnitContrib/licenses/Jetty_license.html  
    pub/System/JSUnitContrib/licenses/lgpl-2.1.txt  
    pub/System/JSUnitContrib/licenses/MPL-1.1.txt  
    pub/System/JSUnitContrib/licenses/mpl-tri-license-c.txt  
    pub/System/JSUnitContrib/licenses/mpl-tri-license-html.txt  
    pub/System/JSUnitContrib/logging.properties  
    pub/System/JSUnitContrib/readme.txt  
    pub/System/JSUnitContrib/testRunner.html  
    pub/System/JSUnitContrib/tests/data/data.html  
    pub/System/JSUnitContrib/tests/data/staff.css  
    pub/System/JSUnitContrib/tests/data/staff.dtd  
    pub/System/JSUnitContrib/tests/data/staff.xml  
    pub/System/JSUnitContrib/tests/jsUnitAssertionTests.html  
    pub/System/JSUnitContrib/tests/jsUnitFrameworkUtilityTests.html  
    pub/System/JSUnitContrib/tests/jsUnitMockTimeoutTest.html  
    pub/System/JSUnitContrib/tests/jsUnitOnLoadTests.html  
    pub/System/JSUnitContrib/tests/jsUnitRestoredHTMLDivTests.html  
    pub/System/JSUnitContrib/tests/jsUnitSetUpTearDownTests.html  
    pub/System/JSUnitContrib/tests/jsUnitTestLoadData.html  
    pub/System/JSUnitContrib/tests/jsUnitTestLoadStaff.html  
    pub/System/JSUnitContrib/tests/jsUnitTestSetUpPages.html  
    pub/System/JSUnitContrib/tests/jsUnitTestSetUpPagesSuite.html  
    pub/System/JSUnitContrib/tests/jsUnitTestSuite.html  
    pub/System/JSUnitContrib/tests/jsUnitUtilityTests.html  

  • Alternatively, manually make sure the dependencies listed in the table below are resolved. None

Contrib Info

Copyright ©: Copyright (C) 2001-6 Edward Hieatt, edward@jsunit.net. Packaged for TWiki 2006, Foswiki 2008 by Arthur Clemens. Directory java removed to reduce package size.
License: GPL, GNU Library or Lesser General Public License (LGPL), Mozilla Public License 1.1 (MPL 1.1)
Dependencies: None
26 Nov 2008 Re-packaged for Foswiki
28 Oct 2006 Version jsunit2.2alpha11
Home: http://foswiki.org/Extensions/JSUnitContrib
Feedback: http://foswiki.org/Extensions/JSUnitContribDev
Appraisal: http://foswiki.org/Extensions/JSUnitContribAppraisal

I Attachment Action Size Date Who Comment
JSUnitContrib.md5md5 JSUnitContrib.md5 manage 162 bytes 11 Aug 2011 - 11:50 ArthurClemens  
JSUnitContrib.sha1sha1 JSUnitContrib.sha1 manage 186 bytes 11 Aug 2011 - 11:50 ArthurClemens  
JSUnitContrib.tgztgz JSUnitContrib.tgz manage 73 K 11 Aug 2011 - 11:50 ArthurClemens  
JSUnitContrib.zipzip JSUnitContrib.zip manage 106 K 11 Aug 2011 - 11:50 ArthurClemens  
JSUnitContrib_installerEXT JSUnitContrib_installer manage 7 K 11 Aug 2011 - 11:50 ArthurClemens  
Topic revision: r1 - 11 Aug 2011, ArthurClemens
The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License    Legal Imprint    Privacy Policy