mattwhitfield / Unitverse

A unit test generation extension for Visual Studio that aims to always produce code that compiles - covering the basic cases automatically and preparing as much as it can for the complex cases.
MIT License
89 stars 20 forks source link

(Re)Generating tests after initial generation is not updating the generated unit test class when using file scoped namespaces #179

Closed AdaTheDev closed 1 year ago

AdaTheDev commented 1 year ago

When using the "Generate file scoped namespaces" config option, if you have previously generated unit tests for a class, it won't then subsequently update the generated tests in any situation. You can delete the generated test file, and generate again from scratch and it does pick up the changes.

Confirmed that it's working fine if you have "Generate file scoped namespaces" set to False.

Repro: 1) Have the Layout - Generate file scoped namespaces configuration option set to True

2) Create a new class:

public class Foo
{
    public Foo(string bar)
    {
        Bar = bar;
    }

    public string Bar { get; }
}

2) Right click -> Generate Tests for Type 'Foo' - generates the tests fine 3) Edit the class to add a 2nd ctor:

private object _woop;

public Foo(object woop)
{
    _woop = woop;
}

4) Shift+Right click a ctor -> "Regenerate test for all constructors..." - focus switches back to the previously generated unit tests, but no changes have been picked up - there is no test for the extra ctor. Same if you Shift+Right click the class and "Regenerate tests for type 'Foo'..."

Deleting the unit test file, and generating from scratch is fine and picks up both ctor's.

Console output from Unitvers shows:

Creating unit test project mapping for 'ExampleProject'.
Found target project 'ExampleProject.UnitTests'.
Adding required assets to target project...
Adding generated items to target project...
Generation complete.

Environment Unitverse 0.170.0.0 VS 2022 17.4.2 .NET 6.0 MSTest

mattwhitfield commented 1 year ago

Sorry about that and, as ever, thanks for the report :) PR incoming