# Unit Test sharing --- ## Practice 題目: 今天是聖誕節就回傳'Merry Xmans', 否則回傳'Today is not Xmas' --- Coding Time {%youtube 4ic6bFOEdzs %} --- ```javascript= function holiday(){ const today = new Date(); const month = today.getMonth() + 1; const date = today.getDate(); if (month === 12 && date === 25) { return 'Merry Xmas'; } else{ return 'Today is not Xmas'; } } ``` --- Coding Time {%youtube 4ic6bFOEdzs %} --- 新增log功能 ```javascript= import { getToday } from "./helper"; export function holiday(){ const {month, date} = getToday(); if (month === 12 && date === 25) { console.log('Merry Xmas') return 'Merry Xmas'; } else{ console.log('Today is not Xmas') return 'Today is not Xmas'; } } ``` --- ## Extract and Override --- ## 驗證方式 1. return value 2. state 3. dependency object --- ## Anti-pattern 1.  過度指定, 測試得東西太細 一改就壞 2.  測試案例彼此有相依性 3.  Test case name只關注input/output 4.  帶著不需要的資訊 --- ## Learned 1. 測試反應使用情境 如果有使用情境就要寫測試 2. 測試 = 使用說明書 3. 測試資料要給有意義的值 4. 測試最重要的邏輯 5. show your intention ---
{"metaMigratedAt":"2023-06-15T11:09:02.597Z","metaMigratedFrom":"YAML","title":"Unit Test sharing","breaks":true,"slideOptions":"{\"transition\":\"slide\"}","contributors":"[{\"id\":\"05a28c9d-1091-41c5-9324-54e80241883b\",\"add\":8691,\"del\":7541}]"}
    260 views