'How to use multiple Program classes in xUnit test project with WebApplicationFactory

I want to use WebApplicationFactory to create hosts for my tests, but I want to create 2 Web Application Factories for two projects I refereed in single XUnit test project.

When I refer only one project then everything is working fine.

But when I refer two projects, it seems that WebApplicationFactory cant recognize which Program class I want to use.

My goal is to have 2 classes for 2 dummy apps (like on the screen) in a single XUnit test project.

It seems that I cant precise which Program class I want to use in WebApplicationFactory with using statement.

Is it possible to create 2 Web Application Factories for different Pragram classes in one XUnit project, and if yes, then how to do this?

SOLVED THIS MYSELF - it seems that XUnit does not recognize that Program class in .NET6 is in a file where there is no namespace declaration. The solution is to create separate file with namespace declaration and 'public partial class Program{ }' inside. Then you are able to use full path in WebApplicationFactory<TestedProjectNamespace.Program>

How I`d like it to look



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source