-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Integration tests documentation add nunit mstest #35328
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
base: main
Are you sure you want to change the base?
Integration tests documentation add nunit mstest #35328
Conversation
@dotnet-policy-service agree |
…om/jonorogers/AspNetCore.Docs into integration-tests-add-nunit-mstest
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.
Pull Request Overview
This PR expands the integration tests documentation to include MSTest and NUnit examples alongside the existing xUnit snippets by updating pivot groups and adding corresponding code samples.
- Added a new pivot group ("Unit testing framework") in the zone-pivot-groups.yml file.
- Introduced multi-framework integration test snippets for xUnit, MSTest, and NUnit across various test files (IndexPageTests, BasicTests, AuthTests, CustomWebApplicationFactory).
- Updated integration tests markdown to reference the new unit-testing-framework pivot group.
Reviewed Changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated no comments.
Show a summary per file
File | Description |
---|---|
aspnetcore/zone-pivot-groups.yml | Added a new pivot group for unit testing frameworks with xUnit, MSTest, and NUnit. |
aspnetcore/test/integration-tests/snippets/xunit/* | Added xUnit integration test snippets with multiple test methods. |
aspnetcore/test/integration-tests/snippets/mstest/* | Added MSTest integration test snippets mirroring the xUnit examples. |
aspnetcore/test/integration-tests/snippets/nunit/* | Added NUnit integration test snippets mirroring the xUnit examples. |
aspnetcore/test/integration-tests/includes/integration-tests9.md | Updated documentation to include new pivot zones for unit-testing-framework. |
aspnetcore/test/integration-tests.md | Added zone_pivot_groups configuration and updated code snippet inclusions for multiple frameworks. |
@benhopkinstech @timdeschryver @profet23 please review |
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.
The examples are looking good to me to me.
For some reason the snipping are not showing up for me while running docfx serve
.
But I do have a couple of remarks (which can be handled in separate PRs I suppose):
- Throughout the article there are still some references to xUnit specifics, e.g. in https://learn.microsoft.com/en-us/aspnet/core/test/integration-tests?view=aspnetcore-9.0#test-app-prerequisites and https://learn.microsoft.com/en-us/aspnet/core/test/integration-tests?view=aspnetcore-9.0#disable-shadow-copying. What do we want to do with this?
- Should the sample be updated in the Samples repo? This means the class
HttpClientExtensions
(which is also referenced in this article) needs to be updated.
[!code-csharp[](~/../AspNetCore.Docs.Samples/test/integration-tests/9.x/IntegrationTestsSample/tests/RazorPagesProject.Tests/IntegrationTests/IndexPageTests.cs?name=snippet5&highlight=7-10,17,20-21)] | ||
:::zone pivot="xunit" | ||
|
||
:::code language="csharp" source="../snippets/xunit/IntegrationTests/IndexPageTests.cs?name=snippet5&highlight=7-10,17,20-21"::: |
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.
For highlights you can do the following:
:::code language="csharp" source="../snippets/xunit/IntegrationTests/IndexPageTests.cs?name=snippet5&highlight=7-10,17,20-21"::: | |
:::code language="csharp" source="../snippets/xunit/IntegrationTests/IndexPageTests.cs" id="snippet5" highlight="7-10,17,20-21"::: |
|
||
:::zone pivot="xunit" | ||
|
||
:::code language="csharp" source="../snippets/xunit/IntegrationTests/BasicTests.cs?name=snippet1"::: |
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 think this is easier to read and recommended, I could be wrong though.
:::code language="csharp" source="../snippets/xunit/IntegrationTests/BasicTests.cs?name=snippet1"::: | |
:::code language="csharp" source="../snippets/xunit/IntegrationTests/BasicTests.cs" id="snippet1"::: |
Maybe tagging wrong person? Happy to take a look. |
Thanks @timdeschryver , I've updated all the snippets to your provided syntax; I can see them properly loading in docfx now.. I also re-formatted the new snippets as they didn't follow the .net coding conventions (love me some K&R braces); so the highlight lines were off. I'd be happy to update the sample instead of adding snippets if you think that would bring more value/be easier to maintain in the future. |
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 looking better, thanks for the updates @jonorogers !
Do you also want to update the code snippets in integration-tests9.md
please.
I verified the code snippets are:
- are correct from a technical side
- are displayed (and highlighted) correctly in the docs
@Rick-Anderson when you have the time can you take a look at my previous comment and determine how you want to proceed with this please?
In summary:
- Do we want to have the samples in the Samples repository?
- Do we want to update the other references to xUnit as well in this article?
aspnetcore/test/integration-tests.md
Outdated
:::zone-end | ||
:::zone pivot="nunit" | ||
|
||
:::code language="csharp" source="integration-tests/snippets/nunit/IntegrationTests/IndexPageTests.cs" id="snippet5" highlight="7-10,17,20-21"::: |
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 needs an extra highlighted line
:::code language="csharp" source="integration-tests/snippets/nunit/IntegrationTests/IndexPageTests.cs" id="snippet5" highlight="7-10,17,20-21"::: | |
:::code language="csharp" source="integration-tests/snippets/nunit/IntegrationTests/IndexPageTests.cs" id="snippet5" highlight="7-10,17,20-22"::: |
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.
Thanks, have updated the PR with the updated integration-tests9.md and both files have the highlighted line added
This PR adds support for xUnit & NUnit into the integration tests documentation; including snippets for all three popular testing libraries (xUnit, MSTest, NUnit). This PR follows the examples of already exisiting MS documentation i.e. https://learn.microsoft.com/en-us/dotnet/aspire/testing/write-your-first-test?pivots=mstest
I'm submitting a PR as suggested by @tdykstra here: #35290 (comment)
Notes:
[AssemblyInitialize]
rather than[ClassInitialize]
when instantiating aWebApplicationFactory
in integration tests, but I opted for equivalence between the three examples.Fixes #35290
Internal previews