I’m curious to if it would be valuable, I’d like to start using QUnit, but I really don’t know where to get started. Actually I’m not going to lie, I’m new to testing in general, not just with JS.
I’m hoping to get some tips to how I would start using unit testing with an app that already has a large amount of JavaScript (ok so about 500 lines, not huge, be enough to make me wonder if I have regression that goes unnoticed). How would you recommend getting started and Where would I write my tests?
(for example its rails app, where is a logical place to have my JS tests, it would be cool if they could go in the /test directory but it’s outside the public directory and thus not possible… err is it?)
Well, start with JsUnit. It sounds like you’re more curious about unit testing in general, though.
The things you get from unit testing (if they’re done right) are:
Unit tests should basically touch any public method in your code. Sometimes you may have reason to test private methods, and I’m sure you can decide when that may be. The goal is simple:
In many ways, your tests should define the functionality of your methods.
Sometimes when people write their unit tests, they intentionally “stub out” any integrated code (i.e., method calls that return other data from a database, file, or business logic) and make them return static data instead. This helps you to feel more confident that you’re only testing the code present in the logic you’re testing.
You may want to read on for more information about good and bad unit testing practices.
Edit: I don’t know much about doing this in Ruby on Rails, but you might consider having a look at what some other people are doing. Ultimately, the tools available to you and the structure of your tests is going to depend on your framework and language.