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

Support co-located test scenarios #1682

Closed
benjaminsampica opened this issue Jan 26, 2025 · 2 comments
Closed

Support co-located test scenarios #1682

benjaminsampica opened this issue Jan 26, 2025 · 2 comments

Comments

@benjaminsampica
Copy link

I'm building pretty small worker services or web api's and am trying to avoid a ton of small test projects. However, when I use TUnit on this same project (using XML attributes in the .csproj to remove test code when going to production) I'm seeing the following warning

/src/App.Worker/obj/Debug/net9.0/TestPlatformEntryPoint.cs(10,66): warning CS7022: The entry point of the program is global code; ignoring 'TestingPlatformEntryPoint.Main(string[])' entry point.

I assume this is the root cause of it not being discovered in Rider, as well as flat out not working via running in the CLI (it instead just runs the actual application). Is it currently possible to use TUnit with tests that are co-located in the same project as production code?

@thomhurst
Copy link
Owner

You'd have to control the entry point to your application somehow.

But if you want control over starting the tests, this code should do it:

var builder = await TestApplication.CreateBuilderAsync(args);
builder.AddTUnit();
using (var app = await builder.BuildAsync())
{
    return await app.RunAsync();
}

@benjaminsampica
Copy link
Author

Works great, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants