1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# source this file in a bash
XUNIT_TESTSUITE_START=0
XUNIT_START=0
XUNIT_TOTAL=0
XUNIT_FAILED=0
XUNIT_SUCCESS=0
XUNIT_TESTCASES_XML=""
## Call this at the start of a testcase.
# \sa xUnit_fail()
# \sa xUnit_success()
xUnit_start() {
XUNIT_START=$(date +%s.%N)
if [ $XUNIT_TESTSUITE_START == 0 ]; then
# very first call: start of a testsuite
XUNIT_TESTSUITE_START=$XUNIT_START
fi
}
## Call this after the testcase finished with a failure.
# \sa xUnit_success()
# \pre xUnit_start() must have been called before
# \param $1 classname
# \param $2 testcase name
# \param $3 testcase result
# \param $4 run result
# \param $5 XML file local to test case for storing its own results
xUnit_fail() {
class=$1
test_case=$2
result=$3
run_result=$4
xmlfile_testcase=$5
currtime=$(date +%s.%N)
time=$(echo "$currtime - $XUNIT_START" | bc -l)
xml="<testcase classname='$class' name='$test_case' Run_result='$run_result' time='$time s' RESULT='$result'></testcase>"
echo -e $xml >> $xmlfile_testcase
XUNIT_TESTCASES_XML="$XUNIT_TESTCASES_XML \n$xml"
XUNIT_FAILED=$((XUNIT_FAILED+1))
}
## Call this after the testcase finished successfully.
# \sa xUnit_success()
# \pre xUnit_start() must have been called before
# \param $1 classname
# \param $2 testcase name
# \param $3 testcase result
# \param $4 run result
# \param $5 XML file local to test case for storing its own results
xUnit_success() {
class=$1
test_case=$2
result=$3
run_result=$4
xmlfile_testcase=$5
currtime=$(date +%s.%N)
time=$(echo "$currtime - $XUNIT_START" | bc -l)
xml="<testcase classname='$class' name='$test_case' Run_result='$run_result' time='$time s' RESULT='$result'></testcase>"
echo -e $xml >> $xmlfile_testcase
XUNIT_TESTCASES_XML="$XUNIT_TESTCASES_XML \n$xml"
XUNIT_SUCCESS=$((XUNIT_SUCCESS+1))
}
## Call this after all testcases have been completed.
# This functions writes out the test report.
# \param $1 filename
xUnit_write() {
filename=$1
tests=$((XUNIT_FAILED+XUNIT_SUCCESS))
timestamp=$(date --iso-8601=seconds)
time=$(echo "$currtime - $XUNIT_TESTSUITE_START" | bc -l)
xml_header="<testsuites><testsuite errors='0' failures='$XUNIT_FAILED' hostname='$(hostname)' name='OAI' skipped='0' tests='$tests' time='$time' timestamp='$timestamp'>"
echo $xml_header > $filename
echo -e $XUNIT_TESTCASES_XML >> $filename
echo "</testsuite></testsuites>" >> $filename
XUNIT_TESTSUITE_START=0
XUNIT_START=0
XUNIT_TOTAL=0
XUNIT_FAILED=0
XUNIT_SUCCESS=0
XUNIT_TESTCASES_XML=""
}