For Javascript some testing-frameworks exist, like JSUnit or js-test-driver. They are fine, but they run the tests in a browser. That's fine, especially to verify your webapp is running in different browsers. But on out continuous-integration-server no window-system (and no browser) is installed. So is there a way to run the tests without the usage of a browser? The best would be to use one of the existing frameworks, so that developers can locally run the tests in their browsers and the continuous-integration-system runs them browserless.
views:
178answers:
4jsTest can be run command line or as an eclipse plugin.
However, be careful, you will not get 100% code coverage using a tool like this if you need to support multiple browsers. Each browser implements JavaScript differently (i.e.: IE). Therefore, the only way to fully test your JavaScript is to run the tests in all browsers that you support.
I believe Canoo WebTest can be run without a browser. It's basically a frontend-testing framework but can be used to test JavaScript as well:
JSpec can be run without a browser (using Rhino). But also supports being run in browsers as well.
http://visionmedia.github.com/jspec/
It also provides a nice specification style syntax:
describe 'ShoppingCart'
describe 'addProduct'
it 'should add a product'
cart.addProduct('cookie')
cart.addProduct('icecream')
cart.should.have 2, 'products'
end
end
end
By running all your unit tests outside of a browser, you also get the benefits of ensuring separation of your logic from the html/presentation layer (useful for web apps, possibly overkill for small scripts).