2013-03-14 73 views
0

我現在都有兩個功能與測試:測試關閉了功能

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功能在哪裏?

+0

看起來像[link](http://stackoverflow.com/questions/2932917) – Jacob 2013-03-14 14:15:51

+0

和[link](http://stackoverflow.com/questions/8569647)爲什麼我不能在我之前找到這個問? – Jacob 2013-03-14 14:36:35

回答

0

你不需要。單元測試的目的是測試行爲而不是執行

所以你測試什麼方法,而不是它如何做。

從這個角度來看,你應該只關心函數調用產生的副作用,就是這樣。