SpecFlow/NUnit/Selenium测试从错误的PWD运行

And*_*ray 0 directory resharper nunit unit-testing

对于我正在开发的新项目,我的团队和我正在尝试使用ReSharper 10,NUnit,SpecFlow和Selenium设置一些功能测试.我们从一个已知的工作项目迁移了一堆旧代码,并使其构建没有问题.

但是,当我们运行代码时,我们不断收到以下错误:

OneTimeSetUp: System.IO.DirectoryNotFoundException : Could not find a part of the path 'C:\Users\Me\AppData\Local\SomeApp\App_Data\SomeApp.db'.

Exception doesn't have a stacktrace
Run Code Online (Sandbox Code Playgroud)

......这不对; 如果它找不到SomeApp.db文件,那应该是失败的C:\MyProjects\SomeApp\SomeApp.Web\App_Data\SomeApp.db!

这种情况下的相关代码在我们的TestSuite.cs类中:

[Binding]
public class TestSuite
{
    private string _currentPath;
    private string _localFile;
    private string _websiteBinPath;
    private string _websiteDataPath;

    // Stuff...

    [BeforeTestRun]
    public static void BeforeTestRun()
    {
        _currentPath = Directory.GetCurrentDirectory() + @"\";
        // Data:
        // <add key="TestWebsiteDataRelativePath" value="..\..\..\SomeApp.Web\App_Data\" />
        // <add key="TestWebsiteBinRelativePath" value="..\..\..\SomeApp.Web\bin\" />
        _websiteBinPath = Path.Combine(_currentPath, ConfigurationManager.AppSettings["TestWebsiteBinRelativePath"]);
        _websiteDataPath = Path.Combine(_currentPath, ConfigurationManager.AppSettings["TestWebsiteDataRelativePath"]);

        //removes the ../../../
        _websiteBinPath = Path.GetFullPath((new Uri(_websiteBinPath)).LocalPath);
        _websiteDataPath = Path.GetFullPath((new Uri(_websiteDataPath)).LocalPath);

        _localFile = _websiteDataPath + "SomeApp.db";

        DoStuffWithLocalFile();
    }

    // Stuff...
}
Run Code Online (Sandbox Code Playgroud)

我们在第一个可执行代码行上设置一个断点,然后逐步执行代码,直到currentPath有一个值 - 该目录currentPath已经存在C:\Users\Me\AppData\Local\JetBrains\Installations\ReSharperPlatformVs14\!

我们已经通过ReSharper选项禁用了Shadow Copy,并且为了额外的措施,我还从ReSharper选项中禁用了MSTest支持.然而,测试项目仍然不会在C:\MyProjects\SomeApp\SomeApp.FeatureTest\bin\Debug目录之外运行.

问: 在什么样的方式才能让我的功能测试项目,从运行C:\MyProjects\SomeApp\SomeApp.FeatureTest\bin\Debug,并且出来的C:\Users\Me\AppData\Local\JetBrains\Installations\ReSharperPlatformVs14\

Ale*_*kin 6

你使用NUnit 3.0吗?如果是这样,请参阅NUnit 3.0 Breaking-Changes页面:

CurrentDirectory不再设置为包含测试程序集的目录.使用TestContext.TestDirectory找到该目录.