Skip to content

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

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

jonorogers
Copy link

@jonorogers jonorogers commented Apr 29, 2025

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:

  • I haven't updated the sample project in AspNetCore.Docs.Samples - this could be useful to add another two testing projects, but I wasn't sure what the scope of this PR should be.
  • Some of the article text still references xUnit; as it's describing the samples project. I'm not sure if this is now confusing, as the pivot groups aren't referencing xUnit if it's not selected.
  • In MSTest I personally favour using [AssemblyInitialize] rather than [ClassInitialize] when instantiating a WebApplicationFactory in integration tests, but I opted for equivalence between the three examples.
  • I noticed that the samples are split up by .NET versions, but I have opted instead to follow the example of the Aspire docs linked above and just provide snippets in C# for the three unit testing frameworks.
  • I have no idea if there is any other code which needs to be modified to support the additional pivot group declaration.

Fixes #35290


Internal previews

📄 File 🔗 Preview link
aspnetcore/test/integration-tests.md Integration tests in ASP.NET Core
aspnetcore/zone-pivot-groups.yml aspnetcore/zone-pivot-groups

@jonorogers
Copy link
Author

@jonorogers please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.

@dotnet-policy-service agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@dotnet-policy-service agree
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@dotnet-policy-service agree company="Microsoft"

Contributor License Agreement

@dotnet-policy-service agree

Copy link
Contributor

@Copilot Copilot AI left a 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.

@Rick-Anderson
Copy link
Contributor

Rick-Anderson commented May 1, 2025

@benhopkinstech @timdeschryver @profet23 please review

Copy link
Contributor

@timdeschryver timdeschryver left a 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):

[!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":::
Copy link
Contributor

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:

Suggested change
:::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":::
Copy link
Contributor

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.

Suggested change
:::code language="csharp" source="../snippets/xunit/IntegrationTests/BasicTests.cs?name=snippet1":::
:::code language="csharp" source="../snippets/xunit/IntegrationTests/BasicTests.cs" id="snippet1":::

@profet23
Copy link

profet23 commented May 2, 2025

Maybe tagging wrong person? Happy to take a look.

@jonorogers
Copy link
Author

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.

Copy link
Contributor

@timdeschryver timdeschryver left a 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?

:::zone-end
:::zone pivot="nunit"

:::code language="csharp" source="integration-tests/snippets/nunit/IntegrationTests/IndexPageTests.cs" id="snippet5" highlight="7-10,17,20-21":::
Copy link
Contributor

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

image

Suggested change
:::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":::

Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add MSTest/NUnit options
4 participants