Skip to content

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.

@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

@GangWang01 GangWang01 merged commit 816499c into dotnet:main Feb 20, 2024
@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