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

Tests generated with Roslyn Source Generators are not discovered #1428

Closed
CptWesley opened this issue Dec 18, 2024 · 4 comments
Closed

Tests generated with Roslyn Source Generators are not discovered #1428

CptWesley opened this issue Dec 18, 2024 · 4 comments

Comments

@CptWesley
Copy link

When using a Roslyn source generator to generate test classes/methods at compile time, TUnit is not able to discover the generated test cases.

An example of a generated source code:

namespace GeneratedNamespace
{
    public class GeneratedClass
    {
        [global::TUnit.Core.TestAttribute()]
        [global::TUnit.Core.ArgumentsAttribute(0, 0, 0)]
        [global::TUnit.Core.ArgumentsAttribute(1, 2, 3)]
        [global::TUnit.Core.ArgumentsAttribute(4, 2, 6)]
        public async Task GeneratedMethod(int n, int m, int __expected)
        {
            var found = n + m;
            await global::TUnit.Assertions.Assert.That(found).IsEqualTo(__expected);
        }
    }
}

Manually copying the generated files into the source directory works fine, so I believe it has something to do with how/when test discovery is performed.

@thomhurst
Copy link
Owner

TUnit uses source generators too. And source generators can't see code from other source generators. So nothing I can do really. This is more an issue for Roslyn I think

@CptWesley
Copy link
Author

Ah, that explains. I didn't expect TUnit to use source generators, so I didn't consider that to be a potential cause.

Linking for context reference: dotnet/roslyn#48358

Copy link
Contributor

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@github-actions github-actions bot added the Stale label Feb 12, 2025
Copy link
Contributor

This issue was closed because it has been stalled for 5 days with no activity.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Feb 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants