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

Clean up ProjectSnapshotManager tests #10051

Merged
merged 7 commits into from
Mar 11, 2024

Conversation

DustinCampbell
Copy link
Member

To facilitate upcoming changes, this pull request audits and cleans up tooling tests that make use of a ProjectSnapshotManager. There is now a single TestProjectSnapshotManager and a unified way to create one. I've also greatly reduced the number of mocks of ProjectSnapshotManagerBase, which will ultimately be going away. In particular, I've rewritten RazorProjectServiceTest, which previously mocked various Razor tooling methods and verified that they were called properly. Because this sort of testing strategy can be particularly brittle when making large changes, so I've rewritten those tests to just use Razor tooling objects and test their outputs. In general, I hope that these will be easier to understand and maintain.

While working RazorProjectServiceTest, I noticed a method that had been made internal for tests, but was actually only ever called by tests. I've gotten rid of that bit.

Recommend reviewing commit by commit.

The testing infrastructure contains no fewer than six TestProjectSnapshotManager classes. This change merges five of them into one and converts the sixth into a mock.
Adds a TestProjectSnapshotManager.GetAccessor() method that produces an IProjectSnapshotManagerAccessor. This is used to clean up a lot of duplicated mocking code.
This change removes all of the extraneous constructors and the Create method from TestProjectSnapshotManager. In their place, CreateProjectSnapshotManager helpers have been added to the various tooling test fixture base classes.
This change makes strides toward removing mocks of ProjectSnapshotManagerBase. The biggest changes are in RazorProjectServiceTest, which has been rewritten to use real Razor objects and test outputs rather than mocking bits and pieces and verifying that members are called.

While working on RazorProjectServiceTest.cs, I noticed a method exposed for tests that was only ever called by tests, so I removed that.
@DustinCampbell DustinCampbell requested a review from a team as a code owner March 8, 2024 00:59
…ager

This addresses code review feedback from @davidwengier to fix the test data in ProjectSnapshotManagerProxyTest to avoid having multiple projects with identical intermediate output paths. In addition, I've rewritten these tests to use an TestProjectSnapshotManager rather than mocking IProjectSnapshotManager.
Thanks to @davidwengier for pointing out that this method can cause tests to be written in a way that hides bugs.
…ions

This change adds TestProjectSnapshotManager.ListenToNotifications(), which makes it easy for test code to listen for project snapshot manager changes and assert the results.
@DustinCampbell DustinCampbell merged commit 4844fbc into dotnet:main Mar 11, 2024
12 checks passed
@DustinCampbell DustinCampbell deleted the clean-up-tests branch March 11, 2024 15:28
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Mar 11, 2024
@RikkiGibson RikkiGibson modified the milestones: Next, 17.10 P3 Mar 25, 2024
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.

3 participants