Showing posts with label unit_test. Show all posts
Showing posts with label unit_test. Show all posts

Wednesday, September 5, 2018

The Legacy Code Change Algorithm

  • Identify change point
  • Identify test point
  • Break dependencies
  • Write test
  • Make change and refactor
Notice that the LAST thing you do is write new code. Most of your work with legacy code is understanding and carefully selecting where to make changes so as to minimize risk and minimize the amount of new test code you have to write to make your target change safely.

參考資料

Saturday, October 8, 2016

從 unit test 到 functional programming

在最近的這分工作,才漸漸有在寫「單元測試」 unit test ,在和其它同事討論寫 unit test 的時候,我們討論到了寫 unit test 之前,就必須先把程式寫成「可以被測試」testable。

怎麼寫程式,程式可以是 testable 呢?
例如,函數儘量就只有透過 input argument 和 output argument 來和外界溝通,不要透過全域變數或是在內部呼叫會有副作用的函數。如此才能確保這個函數只要是相同的輸入,就可以總是產生一樣的輸出。

上述的種種要求,在 functional programming 的領域,就叫做要寫沒有副作用(side effect)的函數。或是叫做純函數 (pure function)。我查了網路之後,發現這個「單元測試」與「函數式編程」的關連性,也早就有許多人在談了。讓我來引用一下他們用的句子:

Writing unit tests is reinventing functional programming in non-functional languages.