Skip to content
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

Move shared unit test code to a shared assembly #9420

Merged
merged 11 commits into from
Feb 20, 2024

Conversation

GangWang01
Copy link
Member

Fixes #8364

Context

As the issue mentions /src/Shared/UnitTests shares functionality in unit tests via shared code files. Actually they should be moved to /src/UnitTests.Shared/Microsoft.Build.UnitTests.Shared.csproj

Changes Made

Assemble share code files with common functions in unit tests from /src/Shared/UnitTests into /src/UnitTests.Shared/Microsoft.Build.UnitTests.Shared.csproj

Testing

Notes

@GangWang01
Copy link
Member Author

There are also some code files with tests shared among multiple projects. For example, src/Shared/UnitTests/ErrorUtilities_Tests.cs is shared in the following test projects.

  • src\Build.UnitTests\Microsoft.Build.Engine.UnitTests.csproj
  • src\Tasks.UnitTests\Microsoft.Build.Tasks.UnitTests.csproj
  • src\Utilities.UnitTests\Microsoft.Build.Utilities.UnitTests.csproj

Is there any difference running the same set of tests in such a shared test code file multiple times in different projects?

Copy link
Member

@rainersigwald rainersigwald left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are also some code files with tests shared among multiple projects. For example, src/Shared/UnitTests/ErrorUtilities_Tests.cs is shared in the following test projects.

  • src\Build.UnitTests\Microsoft.Build.Engine.UnitTests.csproj
  • src\Tasks.UnitTests\Microsoft.Build.Tasks.UnitTests.csproj
  • src\Utilities.UnitTests\Microsoft.Build.Utilities.UnitTests.csproj

Is there any difference running the same set of tests in such a shared test code file multiple times in different projects?

I think this is because the code under test src/Shared/ErrorUtilities.cs is compiled into several product assemblies, so it makes sense to test each of those assemblies. So let's leave it for now. However, as we move that stuff into Framework, we can single-instance the tests.

src/Directory.Build.targets Show resolved Hide resolved
src/UnitTests.Shared/AssemblyInfo.cs Outdated Show resolved Hide resolved
src/UnitTests.Shared/AssemblyInfo.cs Outdated Show resolved Hide resolved
src/Utilities.UnitTests/TaskLoggingHelper_Tests.cs Outdated Show resolved Hide resolved
@GangWang01 GangWang01 marked this pull request as ready for review January 9, 2024 09:51
Copy link
Member

@rainersigwald rainersigwald left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love it!

Copy link
Member

@AR-May AR-May left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

MSBuild.sln Show resolved Hide resolved
@GangWang01 GangWang01 merged commit 816499c into dotnet:main Feb 20, 2024
8 checks passed
@GangWang01 GangWang01 deleted the test-sharedcode branch February 20, 2024 04:22
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.

Move shared unit test code to a shared assembly
3 participants