Question

here is a tricky one:

  • I have a unit test Test(string value) that must be called several times with different parameter values.
  • The list of values to be provided are read from another method GetValues() that is specified in the [Test] attribute of Test()
  • GetValues() must read the content of a file Values.txt in the working directory to return the values
  • the working directory is not the test assembly directory

In order to achieve this, I need to know the working directory when GetValues() is called, but I can't find this inforrmation because:

  • Directory.GetCurrentDirectory() returns the directory of the assembly, not the working directory where nunit is called from,
  • TestContext.CurrentContext.WorkingDirectory is not yet defined, and results in a System.NullReferenceException

I also tried to load the content of the file during the fixture setup but this is called after GetValues(), so no luck: I can find the file but the null pointer exception was already raised.

Does anyone have an idea? Thank you in advance for your help

Cedric.

Était-ce utile?

La solution

From what I could read, this feature will not be available until vestion 3.0, when the working directory should simply not change.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top