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

Create a test context to take away a lot of the repeating plumbing code #260

Merged
merged 5 commits into from
Sep 8, 2024

Conversation

Corniel
Copy link
Contributor

@Corniel Corniel commented Mar 9, 2024

Investigating the unit tests to test the Analyzers, a lot of repeating plumbing code is used. To reduce this, I created a test context. The idea is that is should take care of (most) of the plumbing code:

[Test]
public void Some_test()
{
    using var ctx = Context.ForProject("MyProject.csproj");

    ctx.Analyzer.Build().First().AdditionalFiles
        .Should().BeEquivalentTo("message.txt");
}

The contexts ensures that previous created artifacts (in the bin, and the obj folder) are removed, and logs the Logger to the console if run in DEBUG mode. This will (still) prevent the build logs from being flooded, but gives a nice developer experience while running the tests. What do you think of this?

Obviously, naming is a thing here, and I'm open to suggestions for improvement.

@phmonte
Copy link
Owner

phmonte commented Apr 7, 2024

@Corniel, I liked it, I don't like many projects within the solution, but it is necessary to share with Buildalyzer.Workspaces.Tests.

Is there any reason to keep the old GetProjectAnalyzer method?

I liked the change in the name of the tests too.

@Corniel
Copy link
Contributor Author

Corniel commented Apr 9, 2024

@Corniel, I liked it, I don't like many projects within the solution, but it is necessary to share with Buildalyzer.Workspaces.Tests.

Indeed, otherwise I would not have created a separate project.

Is there any reason to keep the old GetProjectAnalyzer method?

I would say no. But I did not want to change everthing before we agreed on the way to continue.

@Corniel Corniel force-pushed the test-context branch 2 times, most recently from cde2764 to 3415738 Compare April 10, 2024 07:43
@phmonte phmonte added the Ready to Merge Ready to merge label Apr 30, 2024
@Corniel
Copy link
Contributor Author

Corniel commented Jul 31, 2024

Ready to merge. No extra project anymore.

@phmonte phmonte merged commit aa33cf5 into phmonte:main Sep 8, 2024
6 checks passed
@Corniel Corniel deleted the test-context branch September 8, 2024 08:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Ready to Merge Ready to merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants