11

I am writing Integration Test for an ASPNetCore web API project. While reading about it I came across two terminologies, first is

Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory

and second is

Microsoft.AspNetCore.TestHost

References:

  1. https://learn.microsoft.com/en-us/aspnet/core/test/integration-tests?view=aspnetcore-2.1

  2. https://koukia.ca/integration-testing-in-asp-net-core-2-0-51d14ede3968

I am a little confused, why and which kind of setup I should use to test Web API controllers?

3
  • I have same question, have you figured it out? Commented Dec 12, 2018 at 9:29
  • 1
    @kvuong Yes, I am following an older approach (TestHost) because I had my startup class in another assembly (internal) and I had been exposing IWebHostBuilder to my API project. So, in that case, I could not able to use WebApplicationFactory which takes Startup.cs class. And as I have IWebHostBuilder reference I could directly use TestServer(IWebHostBuilder) to create the test client. Hope it will help you. Commented Dec 17, 2018 at 12:10
  • I believe, the former mate is the replacement approach to the latter. This is according to the latest blogs from MightySoft. Commented Mar 1, 2019 at 12:02

1 Answer 1

3

I am following an older approach (TestHost)

because I had my startup class in another assembly (internal) and I had been exposing IWebHostBuilder to my API project. So, in that case, I could not able to use WebApplicationFactory which takes Startup.cs class. And as I have an IWebHostBuilder reference I could directly use TestServer(IWebHostBuilder) to create the test client.

Sign up to request clarification or add additional context in comments.

1 Comment

can you help me with this issue please ? stackoverflow.com/questions/78720994/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.