星期四, 四月 01, 2010

如何使用shunit2來做unit test

如何使用shunit2

(1) 下載 shunit2-2.1.3.tgz
tar zxvf shunit2-2.1.3.tgz


(2) 建議…
在.bashrc中,加上一個alias
alias get_shunit2='cp XXXX/shunit2-2.1.3/src/shell/shunit2 ./'

在 /tmp目錄下做實驗:
get_shunit2 // 這樣可以把需要的shunit2 拷貝到/tmp資料夾下。


(3) 寫一個test suite , 名稱是 test.sh
//////內容/////
#! /bin/sh

testEquality()
{
assertEquals 1 1
}

# load shunit2
. ./shunit2
/////////////

(4) sh test.sh