kward / shunit2

shUnit2 is a xUnit based unit test framework for Bourne based shell scripts.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Failures Reported Wrongly

SomanathThilak opened this issue · comments

Hi

I am running a unit test script containing 3 tests. Suppose two test fails in that ,the output shows failures as 4 .

Log :

test_check_date
test_check_date_2
ASSERT:Test expected:<RPM tcpdmp was installed before 30 days> but was:<RPM tcpdump was installed before 30 days>
shunit2:ERROR test_check_date_2() returned non-zero return code.
test_check_date_3
ASSERT:Test expected:<100> but was:<200>
shunit2:ERROR test_check_date_3() returned non-zero return code.

Ran 3 tests.

FAILED (failures=4)

Ideally it should return 2 test failures.

The number doesn't count how many test functions have failed, but how many times a fail* function was called. Some of your test functions must call those more than once. If you want to avoid that, consider calling return after each fail*.

The behavior is consistent with that for skipping, which counts how many assertions have been skipped:
https://github.com/kward/shunit2/blob/master/README.md#-test-skipping

@rolweber , shouldn't it actually return number of test functions failed?
Can you elaborate the alternative you suggested? From where do you suggest calling return?

Ok. I got it. _shunit_incFailedCount() is called when an asset fails and also when test function returns non-zero return code. So we should use either of the way to report failure.

I believe this was fixed with #140.