比如,對於這樣的情形,我們有一份測試用例,裏面列出了許多測試項目;另有一份測試Log,我們用grep過濾它,得到只包含測試項目名稱的新文件。我們如何判斷,測試的Log已經包含測試項目中所有的測試項呢?或者,我們又多測試了哪些測試項目之外的項目呢?
用Shell腳本做比較方便,腳本如下:
#!/bin/bash
if [ $# -lt 2 ];then
echo "Usage: prog file1 file2"
exit 1
fi
TESTLOG=$1
XMLFILE=$2
cat $XMLFILE |\
while read test_item; do
grep $test_item $TESTLOG > /dev/null
if [ ! $? -eq 0 ];then
echo $test_item does not exist in $TESTLOG
fi
done