How do I customize WebApplicationFactory to use Startup from another project directory?
Using startup, appsettings from this project below. Creating integration test which points to original application startup.
Startup is in this folder along with appsettings, C:\\Test\\Test.WebAPI
new WebHostBuilder()
.UseContentRoot("C:\\Test\\Test.WebAPI")
.UseEnvironment("Development")
.UseConfiguration(new ConfigurationBuilder()
.SetBasePath("C:\\Test\\Test.WebAPI")
.AddJsonFile("appsettings.json")
.Build()).UseStartup<Startup>());
https://fullstackmark.com/post/20/painless-integration-testing-with-aspnet-core-web-api
Which Startup
to use is based solely on what's passed as the type param to UseStartup
. You simply need to reference the correct namespace to route to the class you want to use, just like any other type reference. It has nothing to do with the file system or even which project it exists in (other than those things potentially contributing to the namespace originally).
Remember also that the type param for WebApplicationFactory
is actually TEntryPoint
. It's simply a reference to the project namespace, not an indication of which Startup
class is being utilized. You could sub it with Program
or really any class in the project.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.