vendredi 22 janvier 2016

SpecFlow/NUnit/Selenium tests running from wrong PWD

For a new project I am working on, my team and I are trying to get some Feature Tests set up using ReSharper 10, NUnit, SpecFlow, and Selenium. We migrated a bunch of our old code from a known working project and got it to build without issue.

However, when we run our code, we keep getting the following error:

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

...This isn't right; if it's failing to find the SomeApp.db file, it should be failing from C:\MyProjects\SomeApp\SomeApp.Web\App_Data\SomeApp.db!

The relevant code in this case is in our TestSuite.cs class:

[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 + "HAMS.db";

        DoStuffWithLocalFile();
    }

    // Stuff...
}

We set a breakpoint on the first executable line of code and stepped over code until currentPath had a value - the directory that currentPath had was C:\Users\Me\AppData\Local\JetBrains\Installations\ReSharperPlatformVs14\!

We have already disabled Shadow Copy via the ReSharper options, and for extra measure I disabled MSTest support also from the ReSharper options. Yet, the test project still will not operate out of C:\MyProjects\SomeApp\SomeApp.FeatureTest\bin\Debug directory.

Question: In what way can I get my feature test project to run from C:\MyProjects\SomeApp\SomeApp.FeatureTest\bin\Debug, and not out of C:\Users\Me\AppData\Local\JetBrains\Installations\ReSharperPlatformVs14\?

1 commentaire:

  1. Turning off 'Shadow copy assemblies being tested' option under ReSharper | Options | Unit Testing might do the job.

    RépondreSupprimer