5

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.

Martin R-L
  • 4,039
  • 3
  • 28
  • 28

5 Answers5

8

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.

Jon Adams
  • 24,464
  • 18
  • 82
  • 120
machineghost
  • 33,529
  • 30
  • 159
  • 234
  • +1 Using JS Test driver at the moment, its works great however it is a bit involved to set up, I would only recommend it in projects where the resources are available (not for one-man teams). – Steven de Salas Jan 17 '12 at 16:53
4

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.

ndp
  • 21,546
  • 5
  • 36
  • 52
2

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.

Hemlock
  • 6,130
  • 1
  • 27
  • 37
2

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.

Martin R-L
  • 4,039
  • 3
  • 28
  • 28
  • Let me recommend zombieJS as a framework similar to selenium but based on nodejs and javascript. – Raynos Mar 17 '11 at 01:45
  • +1 Great solution, while there may be more involved solutions that provide bells and whistles including CI testing this will work to get unit testing up and running quickly on 90% projects. – Steven de Salas Jan 17 '12 at 16:41
0

Turboframework uses javascript, jasmine, selenium and runs with node. You can literally create a test project and run web automated tests in less than 10 minutes. To avoid repeating the documentation that is already available, here's the link to a quick start guide:

https://turboframework.org/en/blog/2021-03-03/automate-your-web-application-tests-in-less-than-ten-minutes

Jaume Mussons Abad
  • 706
  • 1
  • 6
  • 20