Changes to AppDomain.CurrentDomain.BaseDirectory after running the test?

In VS2012, I have a bunch of (MS) unit tests that use different xml / text files, which I saved in the same folder as the test file class.

I open these files using File.OpenRead (AppDomain.CurrentDomain.BaseDirectory + "file")

If I run only one test, it works, the file is read.

If I run all the tests at once, BaseDirectory returns a different path (in TestResults / Deploy / currentdatetime / Out) and obviously cannot find the file there.

What to do?

Thanks!

+4
source share
1 answer

, , , Google , .

:

    [ClassInitialize]
    public static void ClassInitialize(TestContext context)
    {
        string deployDir = AppDomain.CurrentDomain.BaseDirectory;
        string[] rows = deployDir.Split(new string[] { "TestResults" }, StringSplitOptions.None);
        string projectPath = rows[0].ToString();
        _path = projectPath + "newpath\\";
    }
-1

All Articles