I'm encountering an inconsistency when running tests with dotnet-test-xunit under netcoreapp10 and under net451.
dotnet test is being executed from outside the project directory, i.e. dotnet test test\MyTestProj (this is the TeamCity plugin behavior). When executed this way, if I pass -f net451, the working directory is test\MyTestProj\bin\Debug\net451\win7-x64. However if I pass -f netcoreapp10, the working directory is unchanged, i.e. outside test\MyTestProj.
I'm not sure if this comes from dotnet-test-xunit or from dotnet cli itself (let me know if it's the latter and I'll move this issue). The net451 behavior seems more correct - tests frequently need to open file resources which they expect to be available etc, but at the very list it seems like this should be consistent.
This likely affects every project type except Desktop, not just .NET Core.
Hi, is there any update? I have that issue in vs 2017.
I created a new .net core class library app. After, I added xunit project.
[Fact] public void Test1() { var x = Directory.GetCurrentDirectory(); }
this method returns C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE but my directory of project is C:\Users\Petrishin\Documents\Visual Studio 2017\Projects\ClassLibrary1.....
Also this case: var location = System.Reflection.Assembly.GetEntryAssembly().Location; var directory = System.IO.Path.GetDirectoryName(location);
directory is C:\Users\Petrishin.nuget\packages\microsoft.testplatform.testhost\15.0.0\lib\netstandard1.5
You cannot safely assume that current directory will ever be correct.
If you want the location of where your DLL lives, you can use typeof(MyUnitTest).GetTypeInfo().Assembly.Location, which will point to on-disk location of the DLL which contains MyUnitTest.
Closed for age.
Most helpful comment
You cannot safely assume that current directory will ever be correct.
If you want the location of where your DLL lives, you can use
typeof(MyUnitTest).GetTypeInfo().Assembly.Location, which will point to on-disk location of the DLL which containsMyUnitTest.