How far can you go with JavaScript testing?

2019-04-12 04:32发布

问题:

I'm somewhat informed with TDD and BDD with Ruby/Rails, but I will eventually need to use some form of testing with my JavaScript code. I use MooTools as a JS framework and I absolutely love how well I can organize and modularize my code with its codebase. But, sometimes, when I add new features to my application, I find that the functionality can easily break from how it worked before.

When it comes to testing JavaScrtpt code, does the testing itself fall short of user interaction? Is it really only to test the ins and outs of method and (emulated) classes in JavaScript? Or is there a UX testing practice where you can write unit tests to see if your application's UX behaviour is performing how it should be? I'm aware that "behaviour" is a broad term, but is there anyway that you can organize your JavaScript tests so that whenever you add something new then you can rest (somewhat) assured that your new code won't break anything from before? How is this done with any of the larger web apps out there?

回答1:

It is perfectly fine, accepted and advised to use unit testing frameworks such as JSSpec or Jasmine (there are many others).

Then, you may do UI unit, functional and sometimes even integration testing with tools such as Ghostbuster or Selenium. These allow you to fake user events and interaction.

Ghostbuster is still quite young, so we don't know so much about “actual” uses, but Selenium is an industry standard (I know it is used at IBM, source: teacher working at IBM).

However, what you can't automatically test is UX. UX stands for User eXperience, and that's not something you test on software, only with real user testing.