Unit tests error on ubuntu for simple dotnet 5 web api tests application
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 281
Description
### Describe the bug
When executing unit tests for web API project on ubuntu 20.04 (latest) it throws exception that the solution root could not be located using application root.
If the same published unit tests project run on the windows platform, then all tests pass without any error. It works as expected.
### To Reproduce
Sample project on GitHub: https://github.com/SamShekhovtsov/webapitests
1) Create simple Web API project and Unit Tests project that test the web API.
2) Publish unit tests project to a folder.
3) create a simple docker container using latest ubuntu image and copy 'publish' folder content into the container 'app' directory
4) install power shell and dotnet 5 on the ubuntu:latest container
5) run unit tests using power shell: dotnet test WebAPIProject1.Tests.dll
### Exceptions (if any)
Failed Get_Success [104 ms]
Error Message:
Unable to create instance of class WebAPIProject1.Tests.WeatherForecastControllerTest. Error: System.InvalidOperationException: Solution root could not be located using application root /app/..
Stack Trace:
at Microsoft.AspNetCore.TestHost.WebHostBuilderExtensions.UseSolutionRelativeContentRoot(IWebHostBuilder builder, String solutionRelativePath, String applicationBasePath, String solutionName)
at Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory`1.SetContentRoot(IWebHostBuilder builder)
at Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory`1.b__20_0(IWebHostBuilder webHostBuilder)
at Microsoft.Extensions.Hosting.GenericHostWebHostBuilderExtensions.ConfigureWebHost(IHostBuilder builder, Action`1 configure, Action`1 configureWebHostBuilder)
at Microsoft.Extensions.Hosting.GenericHostWebHostBuilderExtensions.ConfigureWebHost(IHostBuilder builder, Action`1 configure)
at Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory`1.EnsureServer()
at Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory`1.CreateDefaultClient(DelegatingHandler[] handlers)
at Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory`1.CreateDefaultClient(Uri baseAddress, DelegatingHandler[] handlers)
at Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory`1.CreateClient(WebApplicationFactoryClientOptions options)
at Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory`1.CreateClient()
at WebAPIProject1.Tests.WeatherForecastControllerTest..ctor() in C:\Projects\APIProjectWithUnitTests\WebAPIProject1.Tests\WeatherForecastControllerTest.cs:line 38
### Further technical details
PS /app> dotnet --info
.NET SDK (reflecting any global.json):
Version: 5.0.301
Commit: cc8c0abb32
Runtime Environment:
OS Name: ubuntu
OS Version: 20.04
OS Platform: Linux
RID: ubuntu.20.04-x64
Base Path: /usr/share/dotnet/sdk/5.0.301/
Host (useful for support):
Version: 5.0.7
Commit: 556582d964
.NET SDKs installed:
5.0.301 [/usr/share/dotnet/sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 5.0.7 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 5.0.7 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
To install additional .NET runtimes or SDKs:
https://aka.ms/dotnet-download
PS /app>
Contributor guide
Assessment
This issue has not been assessed yet.