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)?
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/
You might want to try Ghost.py a Python implementation of Phantom.JS. I provides an extension for django built on to of the upcoming LiveServerTestCase.
It relies on PyQt4, so you'll have to copy it to your project's virtualenv.
精彩评论