The Wayback Machine - https://web.archive.org/web/20220202001244/https://github.com/dotnet/aspnetcore/issues/39893
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Starting the Server from WebApplicationFactory #39893

Closed
1 task done
steinbachio opened this issue Jan 31, 2022 · 3 comments
Closed
1 task done

Starting the Server from WebApplicationFactory #39893

steinbachio opened this issue Jan 31, 2022 · 3 comments

Comments

@steinbachio
Copy link

@steinbachio steinbachio commented Jan 31, 2022

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

I am trying to make the Application start from my Test Project with WebApplicationFactory so I can run E2E Tests with Playwright but I can't use it via HTTP. Only the integrated HttpClient (from .CreateClient()) works.

AFAIK thats by design because the Application only starts 'InMemory' and die client is simulating real HTTP.

With .net 5 and earlier it was not that hard to write an WebApplicationFixture that creates the Server and uses the StartUp class.
With .net 6 and Minimal API, StartUp is gone and I am not able to Modify and Start the Application like before.

Describe the solution you'd like

It would be nice to have either documentation on how to achieve this. I could find very few documentation on Integration Tests (which is using the InMemory features) and no official documentation on how to run E2E Tests with any of the Major Testing Frameworks.

Adding a Function to WebApplicationFactory that really runs the application would be great. Extending the Documentation for that would also help.

Additional context

No response

@davidfowl
Copy link
Member

@davidfowl davidfowl commented Jan 31, 2022

I believe @martincostello has a ton of experience with this.

@martincostello
Copy link
Contributor

@martincostello martincostello commented Jan 31, 2022

Hey @steinbachio - I've got a sample repo that you can take a look at for some guidance on how to achieve self-hosting an ASP.NET Core application using Minimal Hosting with WebApplicationFactory and using it to write automated browser tests using Playwright.

You can find the code for it at https://github.com/martincostello/dotnet-minimal-api-integration-testing, with the HttpServerFixture class providing the relevant code for hosting the application with a real HTTP port available for browser testing.

I also did a talk about it at a meet-up last year, which is available on YouTube (the link skips to the specific part of the recording).

Let me know if anything needs any further explanation or isn't clear.

@steinbachio
Copy link
Author

@steinbachio steinbachio commented Jan 31, 2022

@martincostello Wow! Thats exactly what I was looking for!

Somehow I didn't find it in the last days when I was searching for E2E, asp.net core and Playwright. Maybe because its saying Integration Tests.

If you could add this to the official documentation, probably a lot of people would benefit from that!

Now I have what I was looking for. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants