Exclude C# Integration Tests on GitHub Actions

Table Of Contents
Introduction
In software development, it’s crucial to ensure the quality and reliability of your code. Testing plays a significant role in achieving this, and different types of tests can be employed for various purposes. In this post, we will discuss how to exclude C# integration tests from your GitHub Actions workflow to improve the efficiency of your CI/CD pipeline.
Unit Tests vs. Integration Tests
Unit tests are focused on testing individual components or functions in isolation, ensuring that each part of the codebase works as expected. On the other hand, integration tests check how different parts of the system interact and collaborate, validating the overall behavior of the application.
Advantages of Separating Unit and Integration Tests
Separating unit tests and integration tests in the CI/CD pipeline provides several benefits:
- Faster feedback: Unit tests are quicker to execute, enabling developers to receive feedback on their code changes more rapidly.
- Improved test isolation: By separating tests, issues in the codebase can be more easily pinpointed and resolved.
- Better resource management: Integration tests often require more resources, such as databases or external services, which can be better managed by running them separately.
Real-World Scenario
Consider a web application where unit tests cover the individual components, while integration tests validate end-to-end scenarios, including interactions with databases and third-party services. Running integration tests alongside unit tests on every commit can be time-consuming and resource-intensive. Excluding integration tests from the GitHub Actions workflow and running them separately or on a scheduled basis can save time and resources, allowing developers to focus on their code changes.
Excluding Integration Tests in GitHub Actions
To exclude a test project from GitHub actions, you can run the test command with a filter, specifying the namespace of the project you want to exclude:
dotnet test --filter FullyQualifiedName!~name.space.you.want.to.exclude --configuration Release
You can then incorporate this command into your GitHub actions workflow like this:
name: .NET Coreon:push:branches:- main # Your default release branchjobs:build:runs-on: windows-lateststeps:- uses: actions/checkout@v2- name: Setup .NET Coreuses: actions/setup-dotnet@v1with:dotnet-version: 5.0.101- name: Build and Test with dotnetrun: dotnet test --configuration Releaserun: dotnet test --filter FullyQualifiedName!~name.space.you.want.to.exclude --configuration Release
By following these steps, you can efficiently exclude integration tests or any other test project from your GitHub Actions workflow.
Conclusion
By filtering out tests based on their namespace, you can exclude specific test projects from your GitHub actions workflow. This is particularly useful when you want to exclude integration tests from your build process.
Further Reading
For more information on using GitHub Actions with .NET Core, as well as other advanced topics and best practices, consider exploring the following resources:
- GitHub Actions for .NET Core
- GitHub Actions Workflow Syntax
- Running .NET Core Unit Tests with GitHub Actions
- Filtering and Selecting .NET Tests
These resources should provide you with a deeper understanding of how to set up, customize, and optimize your GitHub Actions workflows for .NET Core projects.
Feedback and Questions
We’d love to hear your thoughts on this tutorial! If you have any questions or suggestions for improvement, please don’t hesitate to reach out. You can leave a comment below, or you can contact us through the following channels:
- Email: shady@shadynagy.com
- Twitter: @ShadyNagy_
- LinkedIn: Shady Nagy
- GitHub: ShadyNagy
We’ll do our best to address any questions or concerns you may have. We look forward to hearing from you and helping you make the most of GitHub Actions and .NET Core testing in your projects!







