FuncUnit is a powerful functional testing framework written in JavaScript with a jQuery-like syntax. It provides an approachable way to write maintainable cross browser tests. It is the first functional testing framework written for JavaScript developers by JavaScript developers.
FuncUnit extends QUnit's API with commands like click, type, and drag. The same tests can be run in browser or automated via Selenium.
The following tests that an AutoSuggest returns 5 results.
See it in action! (Make sure you turn off your popup blocker!)
module("autosuggest",{
setup: function() {
S.open('autosuggest.html')
}
});
test("JavaScript results",function(){
S('input').click().type("JavaScript")
// wait until we have some results
S('.autocomplete_item').visible(function(){
equal( S('.autocomplete_item').size(), 5, "there are 5 results")
})
});
FuncUnit works by loading QUnit, FuncUnit, and your tests into a web page. Your application is opened in a separate browser window. The FuncUnit page then drives your application via clicks, types, and drags, reporting pass/fail in the initial FuncUnit test page.
To get started with a basic test, run:
./js jquery/generate/controller Company.Widget
Open company/widget/funcunit.html in a browser. You should see a passing test.
The first thing any FuncUnit page does is load its dependencies and a test. A FuncUnit page:
For more details on setting up a FuncUnit test, check out the [FuncUnit.setup Getting Set Up] guide.
For more details on using FuncUnit without Steal or JavaScriptMVC, check out the [FuncUnit.standalone Using Standalone FuncUnit] guide.
There are four types of commands in any FuncUnit tests:
Tests follow a consistent pattern:
For more information on writing tests, check out the [FuncUnit.writing Writing Tests] guide.
To run this test in browser, open funcunit.html in any browser (and turn off your popup blocker!).
To run the same test automated via Selenium, run:
./funcunit/envjs path/to/funcunit.html
For more information about using Selenium, checkout the [FuncUnit.selenium Automated FuncUnit] guide. Use envjs.bat for Windows users.
Under the hood, FuncUnit is built on several projects:
FuncUnit is designed to let JavaScript developers write tests in an easy to learn jQuery-like syntax. The tests will run in browser, so developers can check for regressions as they work. The same tests also run via Selenium, so QA can automate nightly builds or continuous integration.
TESTING IS PAINFUL. Everyone hates testing, and most front end developers simply don't test. There are a few reasons for this:
FuncUnit aims to fix these problems:
There are many testing frameworks out there, but nothing comes close to being a complete solution for front end testing like FuncUnit does.
new FuncUnit(selector, context) -> funcunit
{String|Function|Object}
FuncUnit behaves differently depending if the selector is a string, a function, or an object.
S.window
or S.window.document to the selector.
{optional:Number}
If provided, the context is the frame number in the document.frames array to use as the context of the selector. For example, if you want to select something in the first iframe of the page:
S("a.mylink",0)
{funcunit}