如何测试setter和getter?
function someClass(){
var data;
this.setData = function(value){
// some complex logic
}
this.getData = function(){
// some complex logic
}
}
是否正确执行setData和getData以测试它在一个测试用例中的回合?
答案 0 :(得分:2)
伪代码:
function yourTest() {
var sc = someClass()
sc.setData(someInputValue1)
assert.equals(someExpectedValue1, sc.getData())
sc.setData(someInputValue2)
assert.equals(someExpectedValue2, sc.getData())
}