I'm new to testing but wholeheartedly realize how important it is. The main issue is that my company has no top-down support for testing at all. That is we don't have any unit testing and just a bit of human testing (I hope I'm using the right terminologies).
I have been trying to get testing started here and have to do it subtly because I'm often asked "when will feature X be done" and therefore can't start the week(s) long project of writing tests for all of our legacy code. Which would need to get rewritten just to provide seams for testing (if I have the concept of 'seams' right). I can, however, sneak a bit of time to test one function. Or at least I think I can.
I'm writing code that basically processes quite a bit of data and then renders it using D3. I would like to write a test for one of the most important functions,
binData. It takes one optional argument (the date to start binning from) and accesses a few properties like
How would I go about doing that?
I think I'll need to create a mock object to hold
this.timestamps (and the other accessed properties). In fact, I imagine several different mock objects which would allow testing of several different datasets. But other than that I'm kinda stuck. In terms of frameworks I've heard of Mocha and Jasmine and Vows but don't know which would be best.
I also don't know how to tie into the massive (and complex) class and module hierarchy and to meet each object's dependencies. That is, the function
binData is in a file called, say,
dataBinner.js which requires all sort of other functions in other files but doesn't explicitly include anything on it's own. Instead, it itself is included in a "manager" file which includes everything that dataBinner.js and the other modules will need. I suppose I'll need to find a way to instantiate everything necessary to test
I'm not afraid to do a bit (or a lot) of reading to better understand things. Any help regarding this specific task of writing a test for
binData or the larger question of how to slowly implement testing in a non-test-friendly place would be much appreciated.
I'm 100% on board, testing-wise. I know it's important and I know that my company is incorrect by not having testing. You'd expect emails that say "fixed regression caused by fixing bug 1413" would trigger something. Or that things that shouldn't take that long take waaaaaay too long ('cause it's spaghetti legacy code).
What I'm asking is given that how do I test my one function which relies on the legacy spaghetti code. That is, how does someone inject a bit of testing into a place without it? I'm guessing that I'll have to write my own testing framework because I'll have to create mocks for the spaghetti legacy code. So that I can instantiate my object and call my function outside of the scope of the application.