We need documentation about how to perform end to end tests for MVC applications using test server in asp.net core 2.0
You can see an outline of the proposed contents in
https://blogs.msdn.microsoft.com/webdev/2017/12/07/testing-asp-net-core-mvc-web-apps-in-memory/
You can find a sample in
https://github.com/aspnet/samples/tree/master/samples/aspnetcore/mvc/testing/TestingMVC
We get questions almost every week on our repos on how to do this, so it's an important one.
I would like to see a more elaborated sample on the docs, showcasing how to tests some APIs and possibly some application that involves a database.
The current coverage for TestServer is (and each has a sample that shows how to use it):
Integration testing
Razor Pages unit and integration testing [has dB (in-memory)]
[Testing controller logic](https://docs.microsoft.com/en-us/aspnet/core/mvc/controllers/testing) [has API & dB (in-memory)]
[EDIT] I need to put in a quicky patch PR on the PrimeWeb one tho. It doesn't have the project file bits for xunit.runner.json (shadowCopy: false) and copying the deps file. I'll put that in by EOD.
There are a few things that https://docs.microsoft.com/en-us/aspnet/core/testing/integration-testing needs to cover.
Without all these things, razor views will not work in most scenarios.
When we attempted to upgrade this one (and one other), we totally dorked the update.
Root cause analysis:
I presume your bullet points for 1 and 2 would be done (not required for this particular sample ... it's middleware ... no Razor views) here :point_right: https://github.com/aspnet/Docs/blob/master/aspnetcore/testing/integration-testing/sample/test/PrimeWeb.IntegrationTests/PrimeWebCheckPrimeShould.cs#L17-L18
... see how, for example, we're doing that config with the RP testing sample :point_right: https://github.com/aspnet/Docs/blob/master/aspnetcore/testing/razor-pages-testing/sample/tests/RazorPagesTestingSample.Tests/IntegrationTests/TestFixture.cs#L28-L32
Isn't all of that going away tho with the new Integration testing bits coming with 2.1? ... I mean if we have these working (with my little patch PR tonight), can we leave these as they are until 2.1 and update all of them with the new testing bits (when 2.1 releases)?
Not sure I understand what you mean.
There is a package coming in 2.1 that streamlines all this setup (setting the content root, copying the deps file, initializing the webhostbuilder in the same way your app does by calling Program.CreateWebHostBuilder) but you still need to prevent shadow copying in your test application (for example with xunit.runner.json in xunit)
That said, our samples should all work for 2.0 so I would hope we update them ASAP as customers will run into this.
Ah ... yes ... the package. I only very very briefly caught wind of it, and what I saw looked great.
I'll get the little patch PR in very soon. I'm finishing up a draft doc, and that little update will take minutes.
I can't really speak to the notion of how well the current Integration testing topic covers all the ins-and-outs of Test Server, per se. I didn't analyze that topic when I did the one for RP testing. I did prefer to keep general testing info mostly out of the RP testing topic ... an attempt to keep it focused on just the bits that pertain to testing that type of app. When I do the patch PR tonight, I'll just mark it as "Addresses" this issue (as oppsed to "Fixes") so that Rick and Scott can take up the issue on the broader coverage.
@guardrex Sounds good. Thanks!
@Rick-Anderson @javiercn I think we've pretty well covered this with all of the work on the integration testing topic in recent weeks. We have a few more little things to do, but those are covered by their own issues.
@guardrex Sounds good to me