开发者

JsTestDriver and legacy javascript. To convert or not?

I inherited a legacy JavaScript library simply written as a list of functions as follow:

function checkSubtree(targetList, objId)
{
    ...
}

function checkRootSubtree(targetList, rootLength, rootInfo, level)
{
    ...
}

To test it with JsTestDriver 开发者_开发百科do I have to 'clean' it to adhere to some JavaScript best practice or can I test it without modification?

Thanks


The HtmlDoc document fragment feature of jsTestDriver helps when unit testing DOM-dependent JavaScript code. You probably want a little HTML chunk to apply those functions to, as you go along.

When you've proven that they work, you'll see ways of making the functions more testable. This is one of the hidden gems of unit testing: emergent software design. Since you want to be able to test your code in isolation, you'll have an incentive to reduce coupling.


You can still test it using JsTestDriver. JsTestDriver is only a test runner, it doesn't require your code to be written in any special way. It's hard to give any advice on actual testing without seeing some code (i.e. function bodies).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜