如何测试二传手和吸气剂?

时间:2016-08-30 16:47:17

标签: unit-testing testing

如何测试setter和getter?

function someClass(){
   var data;

   this.setData = function(value){
       // some complex logic
   }

   this.getData = function(){
      // some complex logic
   }
}

是否正确执行setData和getData以测试它在一个测试用例中的回合?

1 个答案:

答案 0 :(得分:2)

伪代码:

function yourTest() {
  var sc = someClass()

  sc.setData(someInputValue1)
  assert.equals(someExpectedValue1, sc.getData())

  sc.setData(someInputValue2)
  assert.equals(someExpectedValue2, sc.getData())
}