对于我正在开发的一个新项目,我和我的团队试图使用ReSharper 10,NUnit,SpecFlow和Selenium设置一些功能测试。我们从一个已知的工作项目中迁移了一堆旧代码,并且无需重新构建它。SpecFlow/NUnit/Selenium测试从错误的PWD运行
然而,当我们运行我们的代码,我们不断收到以下错误:
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
...这是不对的;如果无法找到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...
}
我们设下的代码的第一个可执行行设置断点,并跨过代码,直到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\
?
这就是我需要做的。仅供参考,上面的调用使用'System.IO.Directory'来获得PWD,但这似乎是更好的方法。 –