c++ - Unit tests in systems programming? -
i start learning/using unit tests in c++. however, i'm having hard time applying concept of tests field of programming.
i'm not writing functions follow predefined input/output pattern, instead, programming on level rather close operating system.
some examples are: find out windows version, create system restore point, query registry installed drives, compress file, or recursively find .log files older x days.
i don't see how hard-code "results" testing function. unit tests possible in case?
the "result" doesn't have constant value, code finds out. example, if compressing file, result file that, when uncompressed, gives original file. test take existing test-file , compress it, , uncompress resulting compressed file, compare 2 files. if result "no difference", it's pass. if files not same, have problem of sort.
the same principle can applied of other methods. finding log-files of course require prepare number of files, , given them different times (using setfiletime or such).
getting windows version should give version of windows using.
and on.
of course, should have "negative" tests whenever possible. if compressing file, happens if try compress file doesn't exist? if disk full (using virtual harddisk or similar can here, filling entire disk may not result in great!). if specification says code should behave in way, verify gives correct error message. otherwise, @ least ensure doesn't "crash", or fail without error message of sort.
Comments
Post a Comment