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

Cannot generate tests for projects having the RootNamespace tag #252

Closed Kilazur closed 1 month ago

Kilazur commented 1 month ago

Describe the bug When trying to "Generate tests" for a project having the RootNamespace tag in its .csproj, an error message popup window appears.

To Reproduce

  1. Create a new project
  2. Click on the project to open the .csproj file, and add <RootNamespace /> inside the PropertyGroup XML node.
  3. Add a method to the automatically created Class1 class (in Class1.cs)
  4. Right-click the project, and click on 'Create unit test project...'
  5. Click on 'Ok' and wait for the unit test project to be created
  6. Right click on the original project, and click on 'Generate tests'

Additional context Error message in popup window: image

Error message in Visual Studio's Output for Unitverse:

Creating unit test project mapping for 'ClassLibrary1'. Found target project 'ClassLibrary1.Tests'. Error while finding type by name: Value cannot be null. Parameter name: sourceNameSpaceRoot at Unitverse.Core.Helpers.NamespaceTransform.Create(String sourceNameSpaceRoot, String targetNameSpaceRoot) at Unitverse.Helper.TargetFinder.FindExistingTargetItem(ISymbol symbol, ProjectItemModel source, ProjectMapping mapping, IUnitTestGeneratorPackage package, IMessageLogger messageLogger, ProjectItem& targetItem, Boolean& wasRedirection) in D:\a\Unitverse\Unitverse\src\Unitverse\Helper\TargetFinder.cs:line 55

.csproj with RootNamespace:

<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <TargetFramework>net8.0</TargetFramework>
        <RootNamespace />
        <Nullable>enable</Nullable>
    </PropertyGroup>

</Project>
Kilazur commented 1 month ago

Note that this is not major by any mean, a simple workaround is to remove RootNamespace before generating the tests, and adding it back afterwards.

But it is slightly annoying 😄

mattwhitfield commented 1 month ago

I am pretty sure I know why that is breaking even without looking at the code 😂

Could you explain a bit about why you have that empty tag and the effect it has - just so I make sure I am not missing something...

mattwhitfield commented 1 month ago

This should be fixed in 0.212. If it doesn't work as you think it should then let me know :)