django 项目中的 Javascript 测试,具有 CI 和覆盖率
我正在开发一个 Django 项目,该项目在设计上需要大量 JavaScript 代码。对于服务器端代码,我们尝试使用单元测试来获得适当的测试覆盖率,并在稍高的级别上使用 Django testclient 进行测试。我们有一个为 CI 运行的 Hudson/Jenkins 服务器,其设置或多或少类似于 这篇文章,为我们提供了测试通过和覆盖率统计数据。
我也希望我们的 javascript 有类似的东西。我希望能够在单元测试级别进行测试,而且还可以在集成/验收测试级别进行测试。后者需要完整的 DOM JS 环境和正在运行的 django 服务器。理想情况下,我希望以某种方式使用 Django 测试客户端,这样我就可以按照我习惯的 Django 测试方式设置服务器状态。我还想从 CI 服务器运行所有测试,这需要某种无头浏览器环境(服务器是没有桌面环境的 Ubuntu)。
我发现了很多东西,但很多感觉它无法在 CI 服务器上运行。而且与 Django 的集成通常不是很好,并且没有对服务器环境做良好的测试隔离。最后,我希望有一个能够以相当快的速度运行的东西,以使我的测试/代码周期尽可能快。
是否有框架可以实现我想要的功能,或者是否有人设法拼凑出一个接近的解决方案?是否有任何既定的最佳实践可以与 Django 结合进行良好的 javascript 测试(即我缺少的 django 人员是否有任何推荐的方法)?
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)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
HtmlUNIT 看起来可以完成您需要的一些操作(即支持 JavaScript 的无头浏览器)。根据“runserver”风格的管理命令来配置它应该不会太难,该命令也会在退出时转储覆盖范围。
http://htmlunit.sourceforge.net/
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/
您可能想尝试 Ghost.py 的 Python 实现 Phantom.JS。我为 django 提供了一个基于即将推出的 LiveServerTestCase 的扩展。
它依赖于 PyQt4,因此您必须将其复制到项目的 virtualenv 中。
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.