-
Notifications
You must be signed in to change notification settings - Fork 556
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
Add Aspire.Hosting.Testing to facilitate integration testing #2310
Conversation
c91c864
to
4269b73
Compare
@ReubenBond do you think there's anything incremental thats worth getting in for p4? |
Yes, it's good to have the basics available in p4. It has caveats like: The app projects won't be launched under the debugger, and ports aren't randomized, so your tests need to be part of the same xunit test collection to make them run sequentially |
Moving to P5 |
@DamianEdwards please take a look / mess about with this |
890bc7f
to
4c014dd
Compare
e9523c6
to
acdda59
Compare
_disposable?.Dispose(); | ||
} | ||
|
||
public void OnError(Exception error) |
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.
???
/// <param name="resourceName">The resource name.</param> | ||
/// <returns>The connection string for the specified resource.</returns> | ||
/// <exception cref="ArgumentException">The resource was not found or does not expose a connection string.</exception> | ||
public static string? GetConnectionString(this DistributedApplication app, string resourceName) |
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.
@davidfowl awareness ... this will break with your incoming async changes.
This is really good comprehensive stuff. Impressed with the approach of using the DiagnosticSource/Listener to extract internal state from the entry point. It is a shame that we need to use the partial class trick to coerce the right accessibility on the entry point. BTW, I am not sure that resource removal is a great example. In your sample you Your code would result in DCP not spinning up the container, but the callbacks would likely blow up. |
Agreed, I've been discussing the inevitable issue you pointed out with @DamianEdwards and @davidfowl. Ideally, we'd have some way to filter out parts of the app model so that smaller bits of the application can be tested. The same issue will arise with replacing parts. Anyhow, I'll remove it from the test - it was mostly there as a discussion point. |
f26e398
to
4d21459
Compare
public DistributedApplicationTestingBuilder(Action<DistributedApplicationOptions, HostApplicationBuilderSettings> configureBuilder) | ||
{ | ||
_factory = new(configureBuilder); | ||
_applicationBuilder = _factory.DistributedApplicationBuilder.Result; |
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 just hangs forever. Are the tests missing using the fixture or something?
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 introduced this issue when trying to make CI tests work. There is a fix PR: #2575
Addresses #1704
This PR adds two types to aid in integration testing of Aspire AppHost projects.
DistributedApplicationTestingBuilder<TEntryPoint>
This type allows you to write tests following the builder pattern. For example, if this is your app host's Program.cs:
Then you can write tests which orchestrate and modify it like so:
For this to work, you currently need to add this snippet to your app host project (eg, at the bottom of Program.cs):
DistributedApplicationTestingHarness<TEntryPoint>
This type is akin to
WebApplicationFactory<TEntryPoint>
, but forDistributedApplicationBuilder
instead of host builders.Here is an example which adds an xUnit fixture which uses the testing harness:
The fixture:
The harness base class offers members to:
DistributedApplication
via theDistributedApplication
propertyHttpClient
, endpoint, or connection string for a resourceTODO:
Microsoft Reviewers: Open in CodeFlow