我目前有两个功能,每个功能都有测试:
function A(x) {
// do A things
return Aresults;
}
function testA() {
// this put A through its test and make sure it does what it's supposed to
}
和
function B(x) {
// do B things which involve using A
return Bresults;
}
function testB() {
// this put B through its test and make sure it does what it's supposed to
}
我现在意识到 A 的唯一用途是在 B 中。所以我想重新考虑以隔离和保护代码:
function B(x) {
function A(x) {
// do A things
return Aresults;
}
// do B things which involve using A
return Bresults;
}
function testB() {
// this put B through its test and make sure it does what it's supposed to
}
我的问题是,既然 A 是 B 的封闭函数,我该如何添加测试?即我的 testA 函数在哪里?