'WebApplicationFactory and release pipeline
I am new to WebApplicationFactory use and want to know
- what is the use of this WebApplicationFactory class for integration tests. as my understanding, it is useful only for mocking external services (this is what we do in unit tests).
Should we use WebApplicationFactory for simple web api integration testing?
- what happens in release pipelines? when i run integration tests (written using WebApplicationFactory) open the web api automatically and uses overrided appsettings set in a custom WebApplicationFactory class. so when i publish the tests code on azure and creates release pipeline stage for integration tests. does the above test code (custom WebApplicationFactory ) override the actual app dll's appsetting. ( i mean does it start the app and use test appsetting logic)
Solution 1:[1]
MSFT has pretty good documentation about integration testing and the usage of WebApplicationFactory to help facilitate this type of testing for Web Applications. This is a good place to learn why integration testing is done and how to do it with WebApplicationFactory.
What is the use of this WebApplicationFactory class for integration tests?
The WebApplicationFactory helps you build an in-memory Http Server and an HttpClient capable of making requests on that server.
By default, WebApplicationFactory will build this server using all the same services and dependencies that are registered in the application you are testing. You can, if desired, modify the services that are registered to the IServiceCollection so that Fakes or Mocks can be used instead of concrete implementations, but this is more of a feature of WebApplicationFactory and not its purpose. Whether you use Mocks or not should depend on what you're trying to test, and whether it's OK to use the application's services for testing purposes.
WebApplicationFactory helps test the configuration and middleware pipeline of your web application in a way that unit tests can't. By making HTTP requests into your in-memory server, you're able to ensure your application and its endpoints are working properly.
What happens in release pipelines?
Your integration tests should be in a separate project from your main application. You don't want the integration test project to be in your release pipeline and, unless you have a good reason to, it shouldn't be published to Azure.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | humbleice |
