minchao / unit-testing

單元測試工作坊

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

單元測試工作坊

課程教材:

https://bit.ly/2ZNs3Jj

目錄

開發環境

若您的電腦未安裝以上工具,也可參考以下提供的開箱即用練習環境。

方案一、Gitpod

如果擁有 Gitpod 帳號,可以按這裡直接開始 Gitpod ready-to-code

方案二、VS Code Remote Development

使用 VS Code Remote Development

參考自 https://code.visualstudio.com/docs/remote/containers-tutorial

安裝 Docker

https://www.docker.com/products/docker-desktop

安裝 VS Code 編輯器

https://code.visualstudio.com/Download

安裝 Remote Development Extension

https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.vscode-remote-extensionpack

啟動開發環境

下載課程原始碼:

git clone https://github.com/minchao/unit-testing

接下來開啟剛剛安裝的 VS Code,在編輯器的左下方會出現一個 Remote status bar 項目。

點擊後,選擇 Remote-Containers: Open Folder in Container...,挑選剛剛 git clone 的 unit-testing 資料夾。

容器即自動編譯並啟動,這裡可能需要等待一點時間。

檢查開發環境

待準備就緒後,您可以在 VS Code 的 Terminal > New Terminal 輸入以下指令,確定是否一切正常:

$ node --version; yarn --version; tsc --version
v14.5.0
1.22.4
Version 3.9.7

安裝依賴套件:

$ yarn

最後,我們來執行一個預先建立的單元測試指令,在 Terminal 中輸入:

$ yarn run test

或使用 VS Code 的 GUI 來執行:

這個 test 指令被定義在 package.json 的 scripts 區段內,它會執行完整的單元測試,並輸出覆蓋率報告到專案的 coverage 資料夾下。 您也可以試試其它指令,例如,單獨執行某一個練習的單元測試。

About

單元測試工作坊


Languages

Language:TypeScript 95.8%Language:Dockerfile 3.2%Language:JavaScript 1.0%