Integration Tests using XUnit.NET - Solution root could not be located using application root

Bhanu Prakash Thunuguntla 31 Reputation points

I have two projects in the solution.

  1. Web API using .NET Core 3.1
  2. Integration Tests using XUnit.NET and .NET Core 3.1, this project has a reference to Web API project

A sample integration test class is here.

public class CustomersControllerTests : IClassFixture<WebApplicationFactory<WebAPIProject.Startup>>  
        public CustomersControllerTests(WebApplicationFactory<WebAPIProject.Startup> factory)  
            _httpClient = factory.CreateClient();  
            _clusterRepository = factory.Services.GetService<IClusterRepository>();              


I developed the integration tests using the following article.

All tests ran fine in Visual Studio. So the integration tests project is put into a Azure DevOps pipeline.
Here are the tasks in the Agent job.

  1. Download Pipeline Artifacts task (to download the build artifacts from build pipeline)
  2. Visual Studio test platfrom installer task
  3. Visual Studio Test task

All tests are failed during execution and here is the stack trace for one of the tests.

System.InvalidOperationException : Solution root could not be located using application root D:\a\r1\a\_ReleaseManagement.API.IntegrationTests-CI\drop\ReleaseManagement.IntegrationTests\Release\.  
[ 00:00:06.59]       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.<EnsureServer>b__20_0(IWebHostBuilder webHostBuilder)  
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()  
/home/vsts/work/1/s/src/UnitTests/ReleaseManagement.IntegrationTests/Api/CustomersControllerTests.cs(29,0): at ReleaseManagement.IntegrationTests.Api.CustomersControllerTests..ctor(WebApplicationFactory`1 factory)  
2020-11-27T09:54:43.4381123Z ##[error][ 00:00:06.59]     ReleaseManagement.IntegrationTests.Api.CustomersControllerTests.CreateCustomer_Success [FAIL]  

Any help on how to resolve this issue so the tests can be executed in azure devops pipeline?

.NET Runtime
.NET Runtime
.NET: Microsoft Technologies based on the .NET software framework.Runtime: An environment required to run apps that aren't compiled to machine language.
1,136 questions
Not Monitored
Not Monitored
Tag not monitored by Microsoft.
36,984 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Brando Zhang-MSFT 3,201 Reputation points Microsoft Vendor

    @Bhanu Prakash Thunuguntla Azure devops is currently not supported in the Q&A forums, the supported products are listed over here: (more to be added later on).

    For the related questions about Azure devops you can ask in here

    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments