You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
At first the tests weren't discovered but that was fixed by setting my "dotnet-test-explorer.testProjectPath" to "**/*.sln"
The tests at this point worked both by running dotnet test, and by using the Test Explorer UI.
However, when I tried to Debug I constantly got errors like this:
----- Debugging test method Prime.UnitTests.Services.PrimeService_IsPrimeShould.IsPrime_ValuesLessThan2_ReturnFalse -----
Microsoft (R) Build Engine version 17.1.0+ae57d105c for .NET
Copyright (C) Microsoft Corporation. All rights reserved.
/usr/share/dotnet/sdk/6.0.200/Microsoft.Common.CurrentVersion.targets(4650,5): error MSB3883: Unexpected exception: [/workspace/unit-testing-using-dotnet-test/PrimeService/PrimeService.csproj]
/usr/share/dotnet/sdk/6.0.200/Microsoft.Common.CurrentVersion.targets(4650,5): error : DirectoryNotFoundException: Could not find a part of the path '/workspace/unit-testing-using-dotnet-test/PrimeService/bin/Debug/net6.0/ref/PrimeService.dll'. [/workspace/unit-testing-using-dotnet-test/PrimeService/PrimeService.csproj]
/usr/share/dotnet/sdk/6.0.200/Microsoft.Common.CurrentVersion.targets(4650,5): error : at Interop.ThrowExceptionForIoErrno(ErrorInfo errorInfo, String path, Boolean isDirectory, Func`2 errorRewriter) [/workspace/unit-testing-using-dotnet-test/PrimeService/PrimeService.csproj]
/usr/share/dotnet/sdk/6.0.200/Microsoft.Common.CurrentVersion.targets(4650,5): error : at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String path, OpenFlags flags, Int32 mode) [/workspace/unit-testing-using-dotnet-test/PrimeService/PrimeService.csproj]
/usr/share/dotnet/sdk/6.0.200/Microsoft.Common.CurrentVersion.targets(4650,5): error : at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize) [/workspace/unit-testing-using-dotnet-test/PrimeService/PrimeService.csproj]
/usr/share/dotnet/sdk/6.0.200/Microsoft.Common.CurrentVersion.targets(4650,5): error : at System.IO.FileSystem.CopyFile(String sourceFullPath, String destFullPath, Boolean overwrite) [/workspace/unit-testing-using-dotnet-test/PrimeService/PrimeService.csproj]
/usr/share/dotnet/sdk/6.0.200/Microsoft.Common.CurrentVersion.targets(4650,5): error : at System.IO.File.Copy(String sourceFileName, String destFileName, Boolean overwrite) [/workspace/unit-testing-using-dotnet-test/PrimeService/PrimeService.csproj]
/usr/share/dotnet/sdk/6.0.200/Microsoft.Common.CurrentVersion.targets(4650,5): error : at Microsoft.CodeAnalysis.BuildTasks.CopyRefAssembly.Copy() [/workspace/unit-testing-using-dotnet-test/PrimeService/PrimeService.csproj]
/usr/share/dotnet/sdk/6.0.200/Microsoft.Common.CurrentVersion.targets(4650,5): error : [/workspace/unit-testing-using-dotnet-test/PrimeService/PrimeService.csproj]
Build FAILED.
/usr/share/dotnet/sdk/6.0.200/Microsoft.Common.CurrentVersion.targets(4650,5): error MSB3883: Unexpected exception: [/workspace/unit-testing-using-dotnet-test/PrimeService/PrimeService.csproj]
/usr/share/dotnet/sdk/6.0.200/Microsoft.Common.CurrentVersion.targets(4650,5): error : DirectoryNotFoundException: Could not find a part of the path '/workspace/unit-testing-using-dotnet-test/PrimeService/bin/Debug/net6.0/ref/PrimeService.dll'. [/workspace/unit-testing-using-dotnet-test/PrimeService/PrimeService.csproj]
/usr/share/dotnet/sdk/6.0.200/Microsoft.Common.CurrentVersion.targets(4650,5): error : at Interop.ThrowExceptionForIoErrno(ErrorInfo errorInfo, String path, Boolean isDirectory, Func`2 errorRewriter) [/workspace/unit-testing-using-dotnet-test/PrimeService/PrimeService.csproj]
/usr/share/dotnet/sdk/6.0.200/Microsoft.Common.CurrentVersion.targets(4650,5): error : at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String path, OpenFlags flags, Int32 mode) [/workspace/unit-testing-using-dotnet-test/PrimeService/PrimeService.csproj]
/usr/share/dotnet/sdk/6.0.200/Microsoft.Common.CurrentVersion.targets(4650,5): error : at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize) [/workspace/unit-testing-using-dotnet-test/PrimeService/PrimeService.csproj]
/usr/share/dotnet/sdk/6.0.200/Microsoft.Common.CurrentVersion.targets(4650,5): error : at System.IO.FileSystem.CopyFile(String sourceFullPath, String destFullPath, Boolean overwrite) [/workspace/unit-testing-using-dotnet-test/PrimeService/PrimeService.csproj]
/usr/share/dotnet/sdk/6.0.200/Microsoft.Common.CurrentVersion.targets(4650,5): error : at System.IO.File.Copy(String sourceFileName, String destFileName, Boolean overwrite) [/workspace/unit-testing-using-dotnet-test/PrimeService/PrimeService.csproj]
/usr/share/dotnet/sdk/6.0.200/Microsoft.Common.CurrentVersion.targets(4650,5): error : at Microsoft.CodeAnalysis.BuildTasks.CopyRefAssembly.Copy() [/workspace/unit-testing-using-dotnet-test/PrimeService/PrimeService.csproj]
/usr/share/dotnet/sdk/6.0.200/Microsoft.Common.CurrentVersion.targets(4650,5): error : [/workspace/unit-testing-using-dotnet-test/PrimeService/PrimeService.csproj]
0 Warning(s)
2 Error(s)
Time Elapsed 00:00:01.27
After reviewing OmniSharps documentation I learned that I need to set my "omnisharp.useModernNet" to true, and that resolved my issue, and I am now able to debug unit tests properly.
So in the end the resolution for me was to modify my .vscode/settings.json file to the following:
Hello,
I had a very difficult time for a while using the "Debug" link in my unit tests.
I created a project using a Development Container, targeting .NET 6.
I then created a class library and unit test project as described here
https://docs.microsoft.com/en-us/dotnet/core/testing/unit-testing-with-dotnet-test
At first the tests weren't discovered but that was fixed by setting my "dotnet-test-explorer.testProjectPath" to "**/*.sln"
The tests at this point worked both by running dotnet test, and by using the Test Explorer UI.
However, when I tried to Debug I constantly got errors like this:
After reviewing OmniSharps documentation I learned that I need to set my "omnisharp.useModernNet" to true, and that resolved my issue, and I am now able to debug unit tests properly.
So in the end the resolution for me was to modify my .vscode/settings.json file to the following:
I hope that helps somebody else too.
The text was updated successfully, but these errors were encountered: