对于简单的 HTML5,我应该使用什么 JavaScript UI 测试框架? jQuery 应用程序?
我打算在业余时间编写一个简单的 HTML5 + JavaScript (jQuery) 应用程序,以便跟上最新的 Web 技术(在工作中它是更高级的 C# 后端内容)。
我希望以过去十年左右的方式进行开发,即 TDD 风格。
作为 HTML/JavaScript 中的 TDD/BDD/AcceptanceTDD 世界的新手,我的问题是:是否有一个很棒的框架或类似框架可以在浏览器中针对网页编写测试(对许多浏览器的开箱即用支持)一个明确的加号)?
我想使用 JavaScript 的原因有两个。 1. 我想学习更多 JavaScript,并且 2. 我想使用与开发相同的语言进行测试。
否则,我可以简单地使用我的 C# 技能并使用 Selenium、WatiN 或类似的框架。
我找到了 Jasmine、QUnit,以及使用 jQuery 自行开发的解决方案MSDN,但无法感受到流程或复杂性,因此建议和第一手经验非常受欢迎。
I'm about to write a simple HTML5 + JavaScript (jQuery) app in my spare time in order to keep up with the latest web technologies (at work it's more advanced C# backend stuff).
I'd like to develop in the same fashion that I've done for the last ten years or so, namely TDD style.
Being new to the TDD/BDD/AcceptanceTDD world in HTML/JavaScript, my question is: is there a great framework or the like for writing test against a web page in a browser (out-of-the-box support for many browsers being a definitive plus)?
The reason I'd like to use JavaScript is two-fold. 1. I'd like to learn more JavaScript, and 2. I'd like to use the same language(s) for the tests as I do for development.
Otherwise, I could simply use my C# skills and use Selenium, WatiN, or a similar framework.
I've found Jasmine, QUnit, and a homegrown solution using jQuery at MSDN, but don't get a feel for the flow nor complexity, so recommendations and first hand experiences are more than welcome.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
JS Test Driver 是 Javascript TDD 书籍推荐的框架奥莱利,我现在正在读。我实际上还没有机会经常使用它,但是:
所以我认为至少值得一试。
JS Test Driver is the framework recommended by the Javascript TDD book from O'Reilly that I'm reading right now. I haven't actually had a chance to play with it much yet, but:
So at the very least it's worth checking out I think.
此时,我推荐 Jasmine。我已经在几个项目中成功使用了它。我还没有真正遇到过太多令人沮丧的情况,即我无法完成某件事(与其他工具不同)。它可以根据您的喜好以不同的配置进行设置——它可以像在浏览器中打开页面一样简单,也可以动态“提供”。
目前有数十种通用工具,但到目前为止,还没有明显的赢家。我已经尝试了其中相当多的方法,并且正如 John Resig 指出的那样,创建一个简单的测试框架并不那么复杂。但添加一些工具以使其变得方便很重要。 Jasmine是我用过最完整的一款,但并不臃肿。
重要注意事项:
您确实不需要使用 Selenium 进行简单的单元测试 - 它使配置复杂化并且更加困难编程模型而不是简单的单元测试框架。
At this point, I'd recommend Jasmine. I've used it successfully on a few projects. I haven't really run up against too many frustrating situations where I just couldn't get something done (unlike other tools). It can be set up in different configurations, depending on your preference-- it can be as simple as opening a page in a browser, or it can be "served" dynamically.
There are dozens of tools out there in general usage-- and so far-- no clear winner. I've tried a quite a few of them, and-- as John Resig points out-- creating a simple testing framework isn't that complicated. But adding some tools to make it convenient is important. Jasmine is the most complete one I've used, but it's not bloated.
Important considerations:
You really do not need to use Selenium for simple unit tests-- it complicates the configuration and is a more difficult programming model than a simple unit testing framework.
我为此苦苦挣扎了很多。我认为 Selenium 是你最好的选择,特别是因为听起来你以前用过它。 JS 的其他内容主要是单元测试。
不要削弱 machineghost 的答案,JS Test Driver 非常适合单元测试。
I've struggled with this a lot. I think Selenium is your best bet especially since it sounds like you've used it before. The other stuff for JS is mostly unit testing.
Not to diminish machineghost's answer, JS Test Driver rocks for unit testing.
我最终使用了 QUnit,因为我发现在
中插入 PUT(被测页面)非常简单,并使用 jQuery 从单元测试中访问它。
这样,除了浏览器本身(逻辑 100% 驻留在客户端)和任何文本编辑器之外,我不需要任何其他外部依赖项。
I ended up using QUnit since I found it very simple to just insert the PUT (Page Under Test) in an
<iframe>
, and use jQuery to access it from the unit tests.That way I don't need any other external dependencies other than the browser itself (the logic resides 100% in the client) and any text editor.