Im trying to get E2E/UI testing (selenium, playwright) to work with my unit testing framework.
The basic idea it to use MSTest and the WebApplicationFactory to spin up a "real server" from within my unit tests. The reason for doing this would be to simply avoid having to deploy/release my application for testing (I guess this could be done by using containers etc, sadly.. Im not allowed to use containers). Im also thinking that doing it this wasy would be a "neat" way of mocking any code that calls external services, and be able to create multiple tests with different scenarios for those external calls.
I have searched the web for a way of doing this, but all I can find are posts about how to do this in previous .Net versions (2.1-5), but since .Net 6 the "startup ceremonial" code has changed and the standard way is now to use the minimal API.
Here is a blog post from Scott.H where he is basically doing exactly what Im planing to do, but with .Net 2.1: https://www.hanselman.com/blog/real-browser-integration-testing-with-selenium-standalone-chrome-and-aspnet-core-21
What I have done so far is creating a custom class that inherits from WebApplicationFactory.
basically:
class MyAppFactory : WebApplicationFactory<Program> {
}
And I can use that perfectly fine for integration testing. However.. the server thats initialized when using that class does not accept http-calls, so I cant reach that using a web browser, and neither can selenium.
I tried to follow Scotts blog post. But for some reason the:
protected override TestServer CreateServer(IWebHostBuilder builder)
Is never called.. (not sure if that has with minimal APIs and .Net 6 to do).
Has anyone managed to use the WebApplicationFactory and .Net 6 Minimal API to spin up an "actual server" in memory that accepts http-calls?