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

Missing example on how to use TestServer with ASP.NET 6 #25263

Closed
benm-eras opened this issue Mar 9, 2022 · 9 comments
Closed

Missing example on how to use TestServer with ASP.NET 6 #25263

benm-eras opened this issue Mar 9, 2022 · 9 comments
Labels
Pri3 Source - Docs.ms Docs Customer feedback via GitHub Issue

Comments

@benm-eras
Copy link

The section titled Test with WebApplicationFactory or TestServer only includes an example of how to use the WebApplicationFactory with .NET 6. Is the TestServer still available in .NET 6? If so, is it possible to use it with Blazor?


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

@dotnet-bot dotnet-bot added ⌚ Not Triaged Source - Docs.ms Docs Customer feedback via GitHub Issue labels Mar 9, 2022
@guardrex guardrex self-assigned this Mar 9, 2022
@guardrex
Copy link
Collaborator

guardrex commented Mar 9, 2022

@benm-eras ... The Blazor (Razor component) test guidance is located in the Blazor node at ...

https://docs.microsoft.com/aspnet/core/blazor/test

AFAICT, there has been work on TestServer for Blazor testing scenarios since that topic went up. The testing guidance was put up ~18 months ago. This is a good time to ask if it's all still valid and good in it's present form or if it will need work. I'll ping Artak offline to see where things stand.

@benm-eras
Copy link
Author

Thanks @guardrex I was looking into starting the app to run integration tests on it with Playwright. I have done this in .NET 5 with Microsoft.Extensions.Hosting.Host.CreateDefaultBuilder() as per the .NET 5 instructions on using TestServer, and it still seems to work with .NET 6, it just struck me as odd that it wasn't in the Docs.

@guardrex
Copy link
Collaborator

guardrex commented Mar 9, 2022

Yes, I'm trying to jog my memory on this subject after 18 months. No issues on this subject have been opened since then IIRC.

Now that you mention it, yes ... I just looked 👀 ... I see/recall now that Playwright is just for the browser automation aspect.

TestServer has had work when problems were reported to the product unit. I see the issues/PRs in their repo.

an example of how to use the WebApplicationFactory with .NET 6

There's a line at the end tho that says ...

The .NET 5 version and .NET 6 version with the WebApplicationFactory are identical by design.

... referring to ...

https://docs.microsoft.com/en-us/aspnet/core/migration/50-to-60-samples?view=aspnetcore-6.0#aspnet-core-6-9

Does that cover your ask here?

@benm-eras
Copy link
Author

I am looking to use the "TestServer" method and the resulting IHost, not so much the WebApplicationFactory which will give you an HttpClient. This is because I need to have the application available at a given URL/Port to point Playwright at.

I see no mention of TestServer or creating an IHost in the .NET 6 section of the page. As I say my existing .NET 5 code seems to work:

var host = Microsoft.Extensions.Hosting.Host
    .CreateDefaultBuilder()
    .UseEnvironment(this.Environment)
    .ConfigureAppConfiguration(b => {  /* do app config */ })
    .ConfigureWebHostDefaults(b=> b.UseUrls(myUrl).UseStartup<MyStartup>())
    .ConfigureServices((b,s) => { /* add stuff to DI container */ })
    .Build();

await host.StartAsync();

I can then point Playwright (or my browser) to myUrl and I am good to go. So if you tell me that the .NET 6 version of this is identical to .NET 5 I will be a happy camper, though I feel that last sentence needs amending to explicitly mention TestServer/IHost?

@guardrex
Copy link
Collaborator

guardrex commented Mar 9, 2022

I see. They did place a Q&A here ...

https://docs.microsoft.com/en-us/aspnet/core/migration/50-to-60?view=aspnetcore-6.0&tabs=visual-studio#faq

Scroll down to ...

Rick, I'm going to leave this up to you if you want to make further updates. I thought for a moment that this was more directly Blazor-related, but the team is still recommending our Blazor guidance for the component testing aspects. This issue is about TestServer migration coverage, so it's not really in my wheelhouse.

@guardrex guardrex removed the PU label Mar 9, 2022
@guardrex guardrex removed their assignment Mar 9, 2022
@benm-eras
Copy link
Author

Ah I see, I still don't think that is very clear as I don't think I would be able to use the WebApplicationFactory<TEntryPoint> to do integration testing with Playwright (or similar) unless I am missing something? Where they link to "[Test with WebApplicationFactory or TestServer]"(https://docs.microsoft.com/en-us/aspnet/core/migration/50-to-60-samples?view=aspnetcore-6.0#twa) there is no advice on TestServer for .NET 6.

Everything is working as I would expect, but I just think the Docs need some more information on .NET 6 and TestServer. Thanks for your time regardless.

@guardrex
Copy link
Collaborator

guardrex commented Mar 9, 2022

Yeah ... Rick will be along in a bit to see if a line (and/or example) makes sense.

What I'm going to do is make a note on a tracking issue that I use for Blazor docs to provide guidance about the TestServer setup for Playwright (probably including the non-TestServer Blazor WASM case) or cross-link to anything helpful on it in Playwright docs (although I doubt that they say anything really about this aspect). We might end up having full working examples in the Blazor topic, regardless of what's done with the migration coverage.

@benm-eras
Copy link
Author

Brilliant, thanks Luke

@Rick-Anderson
Copy link
Contributor

This will be covered in #27089

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Pri3 Source - Docs.ms Docs Customer feedback via GitHub Issue
Projects
None yet
Development

No branches or pull requests

4 participants