mercredi 8 juillet 2015

Integration testing for reading a file

I want to make sure that my C# program reads a file as expected. How should I test this? I am assuming I just call my function (which accesses the file system) and see the output when a file exist and when it doesn't. Should I instead abstract the file system out?

Should I even bother testing this (since I am basically testing if StreamReader.ReadLine works)?

My function looks like this (filePath, filePath2, a and b are arguments to the function)

        try
        {
            TextReader tr = new StreamReader(filePath);

            a = tr.ReadLine();
            b = tr.ReadLine();
            tr.Close();
        }
        catch (Exception ex)
        {
            error = GetError(ex);
        }
        if (error != "") {
            File.WriteAllText(filePath2+"Error.txt", error);
        }

Aucun commentaire:

Enregistrer un commentaire