Fault injection for testing?

Attila Rajmund Nohl attila.r.nohl@REDACTED
Mon Dec 20 14:32:09 CET 2010


Hello!

Testing error handling is complicated, because it might be hard to
cause the error situation in the first place, which in my case it's a
file writing error:

    case file:write_file(FileName, <<Index:8/integer>>) of
	ok -> ok;
	Error ->
	    io:format(standard_error, "~p ~p Error: '~p' ~n", [?MODULE, ?LINE, Error]),
	    exit(open_lastwritten_file)
    end.

I could modify my code to fail is some debug flag is turned on, but it
has a (minor) performance impact. My other idea is to make sure that
the write_file fails by injecting the fault into the OTP library, i.e.
before the testcase runs in the automatic tests, load a faulty 'file'
module where the write_file function fails (I happen to know the
filename, so it won't fail for other uses), execute the testcase, then
remove the faulty file module.

Do you have any other ideas on how to test these kind of error
handling code? Testing the function separately, outside the whole
application doesn't do it, because it wouldn't detect possible
deadlocks (the original version of this code actually had a deadlock).


More information about the erlang-questions mailing list