Buildalyzer icon indicating copy to clipboard operation
Buildalyzer copied to clipboard

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

Open Corniel opened this issue 1 year ago • 3 comments

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.

Corniel avatar Mar 09 '24 21:03 Corniel

@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.

phmonte avatar Apr 07 '24 05:04 phmonte

@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 avatar Apr 09 '24 19:04 Corniel

Ready to merge. No extra project anymore.

Corniel avatar Jul 31 '24 07:07 Corniel