Best practices for testing functions that opens files

simendsjo via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Aug 5 23:57:04 PDT 2014


On 08/06/2014 01:22 AM, splatterdash wrote:
> Hi all,
> 
> Is there a recommended way to test functions that opens and iterates
> over files? The unittest block seems more suited for testing functions
> whose input and output can be defined in the program itself. I'm
> wondering if there is a better way to test functions that open files
> with specific formats.
> 
> Thanks before :).

Split it to several functions:

  ubyte[] readFile(string file) {...}

  MyFormat parseData(ubyte[] data) { ... }

This way you have very little logic where the files are read, and you
can easily unittest your parsing.


More information about the Digitalmars-d-learn mailing list