Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript testing within django project, with CI and coverage

I'm working on a Django project that by design is pretty javascript heavy. For the serverside code we try to have decent test coverage by using unittests, and on a slightly higher level have tests using the Django testclient. We have a Hudson/Jenkins server running for CI, with stuff set up more or less along the lines of this article, giving us test pass and coverage stats.

I would like to have something similar for our javascript too. I would like to be able to test on unit-test level, but also on integration/acceptance test level. The latter would require a full DOM JS environment and a django server that's running. Ideally I would want to somehow use the Django test client so I can set up the serverstate in the way I'm used to for Django tests. I would also like to run all of the tests from the CI server, which would require some sort of headless browser environment (server is Ubuntu without a desktop environment).

I have found a bunch of stuff, but a lot feels like it couldn't run on the CI server. Also the integration with Django often isn't great, and don't do good test isolation for the server environment. Finally I would ideally like something that works at a pretty good pace, to keep my test/code cycle as quick as possible.

Are there frameworks that do what I want or has anybody managed to cobble together a solution that comes close? And are there any established best practices in general for doing good javascript testing in combination with Django (i.e. are there any recommended approaches from the django folks I'm missing)?

like image 548
Shabaz Avatar asked Jun 14 '11 11:06

Shabaz


1 Answers

HtmlUNIT looks like it might do some of what you need (ie a headless browser that supports JavaScript). It shouldn't be too hard to rig this up against a 'runserver' style management command that also dumps coverage on exit.

http://htmlunit.sourceforge.net/

like image 123
Tom Christie Avatar answered Oct 13 '22 00:10

Tom Christie