对于简单的 HTML5,我应该使用什么 JavaScript UI 测试框架? jQuery 应用程序?

发布于 2024-10-08 08:04:54 字数 670 浏览 2 评论 0原文

我打算在业余时间编写一个简单的 HTML5 + JavaScript (jQuery) 应用程序,以便跟上最新的 Web 技术(在工作中它是更高级的 C# 后端内容)。

我希望以过去十年左右的方式进行开发,即 TDD 风格。

作为 HTML/JavaScript 中的 TDD/BDD/AcceptanceTDD 世界的新手,我的问题是:是否有一个很棒的框架或类似框架可以在浏览器中针对网页编写测试(对许多浏览器的开箱即用支持)一个明确的加号)?

我想使用 JavaScript 的原因有两个。 1. 我想学习更多 JavaScript,并且 2. 我想使用与开发相同的语言进行测试。

否则,我可以简单地使用我的 C# 技能并使用 Selenium、WatiN 或类似的框架。

我找到了 JasmineQUnit,以及使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

゛时过境迁 2024-10-15 08:04:54

JS Test Driver 是 Javascript TDD 书籍推荐的框架奥莱利,我现在正在读。我实际上还没有机会经常使用它,但是:

  • 一个写了一本关于 JS 测试的书的家伙推荐了它
  • 它有一个非常好的功能集(跨多个浏览器运行的自动化测试是关键)
  • 它来自 Google(爱他们或恨他们,他们有很多聪明的 JS 人员在那里工作)

所以我认为至少值得一试。

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:

  • A dude who wrote a book on JS testing recommends it
  • It has a very nice feature set (automated test running across multiple browsers being key)
  • It comes from Google (love 'em or hate 'em, they have a lot of smart JS people working there)

So at the very least it's worth checking out I think.

演出会有结束 2024-10-15 08:04:54

此时,我推荐 Jasmine。我已经在几个项目中成功使用了它。我还没有真正遇到过太多令人沮丧的情况,即我无法完成某件事(与其他工具不同)。它可以根据您的喜好以不同的配置进行设置——它可以像在浏览器中打开页面一样简单,也可以动态“提供”。

目前有数十种通用工具,但到目前为止,还没有明显的赢家。我已经尝试了其中相当多的方法,并且正如 John Resig 指出的那样,创建一个简单的测试框架并不那么复杂。但添加一些工具以使其变得方便很重要。 Jasmine是我用过最完整的一款,但并不臃肿。

重要注意事项:

  • 设置:不要采用开箱即用的风格无法轻松工作的工具
  • :使用在其他测试工具的上下文中对您有意义的工具。例如,如果您使用 BDD 工具,请找到 BDD Javascript 框架。这可能是框架中最大的差异——不妨选择一个具有您喜欢的语法的框架。
  • 跨浏览器:测试应该跨浏览器工作
  • 自动化:您应该能够在一个或多个浏览器中编写测试运行脚本
  • 来测试基于时间的代码——如果您的 Javascript 具有与时钟相关的行为(如动画),拥有一个测试框架可以促进这是很好的
  • 模拟: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:

  • set up: don't adopt a tool that doesn't work easily out of the box
  • style: use a tool that makes sense to you in the context of the rest of your testing tools. For example, if you use BDD tools, find a BDD Javascript framework. This is probably the biggest variance in the frameworks-- might as well pick one that has a syntax you like.
  • cross-browser: the tests should work across browsers
  • automation: you should be able to script the running of the tests in one or multiple browsers
  • testing time-based code-- if you Javascript has behavior tied to the clock (as in animations), having a testing framework the facilitates this is nice
  • mocking: jasmine has a nice mocking support that really helps

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.

久光 2024-10-15 08:04:54

我为此苦苦挣扎了很多。我认为 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.

束缚m 2024-10-15 08:04:54

我最终使用了 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文