-
Notifications
You must be signed in to change notification settings - Fork 2.1k
[Fixes #6233] Productionize and harden our functional testing infrastructure #6433
Conversation
@@ -0,0 +1,38 @@ | |||
using System.Net; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
license header
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="$(AspNetCoreVersion)" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Testing" Version="$(AspNetCoreVersion)" /> | ||
<PackageReference Include="xunit" Version="$(XunitVersion)" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we drop Microsoft.AspNetCore.Testing
and xunit
from here? I know we will get feedback about bundling xunit with this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I started with the bundled approach as its what we talked about for simplicity. We can definitely make it two packages
Microsoft.AspNetCore.Mvc.Testing and Microsoft.AspNetCore.Mvc.Testing.Xunit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not convinced that there's any need for an xunit specific package. The most valuable piece of this is the test fixture and that's not xunit specific.
|
||
<ItemGroup> | ||
<Content Include="build\**\*.targets" Pack="true" PackagePath="%(Identity)" /> | ||
<Content Include="build\xunit.runner.json" Pack="true" PackagePath="%(Identity)" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure we should be overriding users xunit.runner.json
file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This only includes it in the package. That said, what we can do is look in the output folder if an xunit.runner.json file exists and only if it doesn't, we can copy ours to the output.
} | ||
while (directoryInfo.Parent != null); | ||
|
||
throw new Exception($"Solution root could not be located using application root {applicationBasePath}."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is really nice
|
||
builder.UseStartup<TestStartup<TStartup>>(); | ||
|
||
return new TestServer(builder); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to have these verify that the .deps
file is present (and anything else required). This is the most common issue that our users run into.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could add checks based on whether the user called UseApplicationAssemblies and maybe we can do something to verify the xunit configuration.
There are a few ways of configuring XUnit, not only xunit.runner.json so we can't really tell for sure if shadowCopy (what we care about) is disabled.
Are you ok if we copy xunit.runner.json by default (if the file does not exist on the output) and we provide a property on MSBuild to disable it? We can add a validation in code that checks for xunit.runner.json on the current directory and prints to the console in case its not there or doesn't contain the values that we need. (We can disable the logging to with an environment variable, for the case you go "i know what i'm doing" all the way)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would really prefer that this package doesn't have anything related xunit anything in it. I think it's just not needed, and if we stick xunit stuff in here users of other testing frameworks going to want it taken out.
Follow my reasoning for a set.
- We have an msbuild targets file that copies the deps file
- Make it an msbuild error if your 'app' project doesn't have a deps file
- Then at runtime if you don't have a deps file the only possibility is that you're shadow copied. This should throw an exception and tell you to turn off shadow copying.
/// A middleware that ensures web sites run in a consistent culture. Currently useful for tests that format dates, | ||
/// times, or numbers. Will be more useful when we have localized resources. | ||
/// </summary> | ||
public class CultureReplacerMiddleware |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to pull a bunch of this stuff out of the Mvc.Testing
namespace into something more obscure. You really only need a few of these classes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, pretty much everything but WebApplicationBuilder can be on the .Internal namespace
/// XUnit fixture for bootstrapping an application in memory for functional end to end tests. | ||
/// </summary> | ||
/// <typeparam name="TStartup">The applications startup class.</typeparam> | ||
public class WebApplicationTestFixture<TStartup> : IDisposable where TStartup : class |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's nice that we can ship this without any direct xunit dependency.
@@ -0,0 +1,41 @@ | |||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we use this in our functional test? So we test the tester?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do but through a direct import, due to the fact that target files are only automatically imported for package references, we'll have some E2E tests for this on the identity repo.
assembly dependencies in websites to their corresponding bin/{config}/refs folder we need to re-calculate | ||
reference assemblies for this project so there's a corresponding refs folder in our output. Without it | ||
our websites deps files will fail to find their assembly referenes. | ||
--> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this just about our stuff?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about that, I just copied all the custom stuff from the functional test project into the targets file. @pranavkm any idea what this comment is for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a great start. Feel free to do an initial check in and then do follow ups for issues, or resolve stuff now if you'd prefer that.
services.AddTransient<HtmlEncoder, HtmlTestEncoder>(); | ||
services.AddTransient<JavaScriptEncoder, JavaScriptTestEncoder>(); | ||
services.AddTransient<UrlEncoder, UrlTestEncoder>(); | ||
services.TryAddTransient<HtmlEncoder, HtmlTestEncoder>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't we want to force add these (and not TryAdd)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's why they are added before startup configure services run. It tests that even if you do it this way it will work.
Adds APIs for bootstrapping an application in memory.
Integration with our current functional test infrastructure is pending.
Open questions: