Integration Testing ASP.NET Core Minimal APIs
Overview
The dotnet-minimal-api-integration-testing
project is a sample repository crafted to showcase techniques for integration testing with ASP.NET Core applications that utilize the minimal API feature introduced in .NET 6. The project provides a practical demonstration by implementing a simple Todo list application using various technologies such as Entity Framework Core with SQLite for data handling, GitHub OAuth for authentication, Razor Pages for UI, and TypeScript for scripting.
Features and Components
Minimal APIs
The project employs ASP.NET Core's minimal APIs, which simplify the development process by reducing the boilerplate code required for creating RESTful services. This aligns with the broader aim of the .NET platform to improve developer productivity.
Core Technologies
-
Entity Framework Core & SQLite: The backend data operations in the project are handled using EF Core with SQLite as the database provider. This combination offers a lightweight and efficient data management solution ideal for development and testing scenarios.
-
GitHub OAuth Authentication: Authentication within the Todo App is managed through GitHub's OAuth, providing a secure and robust way for users to log in via their GitHub account.
-
Razor Pages: This feature of ASP.NET Core is used to create the user interfaces of the application, giving the Todo list app a clean and interactive front-end.
-
TypeScript: The project integrates TypeScript for any necessary client-side scripting, offering the benefits of type safety and modern JavaScript development workflows.
Testing and Libraries
To ensure the robustness and reliability of the application, the project includes extensive integration tests covering both API and UI components. These tests leverage several open-source libraries and technologies:
- Coverlet: For measuring code coverage, ensuring that the tests adequately cover the application's codebase.
- HttpClientFactory & HttpClient Interception: These tools help manage outbound HTTP requests in tests, offering flexibility in simulating network conditions and responses.
- Playwright: Provides automated UI testing capabilities that enable cross-browser testing and verifies the application’s interface functionalities.
- ReportGenerator: Helps in generating code coverage reports, making it easy to visualize the areas of the application covered by tests.
- Shouldly and Xunit: Support the project's unit and integration testing efforts, offering easy-to-read test assertions and a comprehensive testing framework.
- Xunit Logging: Facilitates better logging capabilities within tests, providing deeper insights during the test runs.
Debugging and Local Development
The project outlines steps for local debugging, especially emphasizing the importance of setting up a GitHub OAuth application to generate ClientId
and ClientSecret
keys. Developers are advised to manage these sensitive pieces of information using .NET's User Secrets feature to avoid them being exposed in source control.
Building and Running Tests
For developers interested in building and testing the application themselves, it requires Git and a compatible .NET SDK (version 8.0.100 or later) installed on their machine. The repository provides a build script, build.ps1
, enabling seamless test execution and project compilation through simple command-line instructions.
Contributing and Feedback
The project is open to community feedback and contributions. Issues, suggestions, and improvements can be contributed through its GitHub repository, allowing for community-driven evolution and enhancement.
Acknowledgements and License
The project acknowledges contributions from individuals like David Fowler from the ASP.NET Core team, who assisted in resolving technical challenges. It is licensed under the Apache 2.0 license, ensuring it remains open for public use and modification.
This comprehensive integration testing example provides developers with a robust foundation for testing minimal API features in ASP.NET Core applications, helping them to deploy reliable, maintainable, and high-quality software.