vendredi 8 mai 2015

Writing File in Unit-Test: Single-Unittest working, but not on all

We have some Code, which helps us to write the Data we test against into some JSON-Files.

My Code is quite straightforward:

internal static void WriteDataSourcesToJson(IEnumerable<ReportDataSource> dataSources, string jsonFilePath)
{
    lock (_lockObject)
    {
        string jsonString = JsonConvert.SerializeObject(dataSources);

        using (var fs = new FileStream(jsonFilePath, FileMode.OpenOrCreate))
        using (var sw = new StreamWriter(fs))
        {
            sw.Write(jsonString);
        }
    }
}

It works fine, if I run single tests, but as soon as I select "Run All" on the Class, it seems like the code gets ignored without a warning. I thought about a Threading-Problem, but the Lock doesnt help nor do I get an error-message.

Is the "Run all" kindahow handled different than running a single Unit-Test?

Aucun commentaire:

Enregistrer un commentaire