HomeContact

Exclude C# Integration Tests on GitHub Actions

By Shady Nagy
Published in dotnet
August 17, 2021
2 min read
Exclude C# Integration Tests on GitHub Actions

Table Of Contents

01
Introduction
02
Unit Tests vs. Integration Tests
03
Advantages of Separating Unit and Integration Tests
04
Real-World Scenario
05
Excluding Integration Tests in GitHub Actions
06
Conclusion
07
Further Reading

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:

  1. Faster feedback: Unit tests are quicker to execute, enabling developers to receive feedback on their code changes more rapidly.
  2. Improved test isolation: By separating tests, issues in the codebase can be more easily pinpointed and resolved.
  3. 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 Core
on:
push:
branches:
- main # Your default release branch
jobs:
build:
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.101
- name: Build and Test with dotnet
run: dotnet test --configuration Release
run: 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:

  1. Email: shady@shadynagy.com
  2. Twitter: @ShadyNagy_
  3. LinkedIn: Shady Nagy
  4. 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!


Tags

#Github#Github Action#Github Actions#microsoft#dotnet#dotnet core#unit test#Integration Test#C##csharp

Share


Previous Article
Angular Search with Delay
Shady Nagy

Shady Nagy

Software Innovation Architect

Topics

AI
Angular
dotnet
GatsbyJS
Github
Linux
MS SQL
Oracle

Related Posts

Unraveling Performance Bottlenecks in .NET Applications A Deep Dive with Code Examples
Unraveling Performance Bottlenecks in .NET Applications A Deep Dive with Code Examples
December 31, 2023
1 min

Quick Links

Contact Us

Social Media