To run tests for the open-telemetry/opentelemetry-dotnet project, follow the steps below.

Prerequisites

Ensure the following tools are installed on your system:

  • .NET SDK (version compatible with the project)
  • PowerShell or a Bash shell

Step 1: Clone the Repository

Start by cloning the GitHub repository to your local machine.

git clone https://github.com/open-telemetry/opentelemetry-dotnet.git
cd opentelemetry-dotnet

Step 2: Restore Dependencies

Use the .NET CLI to restore the project dependencies. This step ensures that all the required packages are installed before running the tests.

dotnet restore

Step 3: Build the Project

Compile the project to ensure all source code is functional and that any changes have not introduced compilation issues.

dotnet build

Step 4: Running Unit Tests

Navigate to the test project directory if necessary. The test projects are usually located in the test folder. Check for .csproj files to run tests in specific test projects. Use the following command to run the tests:

dotnet test test/OpenTelemetry.Testing/OpenTelemetry.Testing.csproj

You can also run all tests from the root directory using:

dotnet test

Step 5: Running Tests with Coverage

If code coverage is required when running the tests, you can use the coverlet tool. Ensure that it is installed globally or referenced within the project. Run the tests while generating coverage reports with:

dotnet test /p:CollectCoverage=true /p:CoverletOutput=./testresults/coverage/ /p:CoverletOutputFormat=opencover

Be sure to check the output directory for the coverage reports.

Step 6: Running Specific Test Cases

If you need to run a specific test case or filter tests based on names or categories, use the --filter argument. Here’s a command to run a specific test by its name:

dotnet test --filter "FullyQualifiedName~YourNamespace.Tests.YourTestClassName.YourTestName"

Step 7: Viewing Test Results

After running the tests, the results will be displayed in the console. Look for output like the following:

Test run for path/to/testproject.dll
...
Passed!   10
Failed!   2
...
Total tests: 12

If using a format for reports, check the respective output directory to find detailed logs and coverage files.

Additional Test Strategies

  • Continuous Integration: Integrate test runs in your CI/CD pipelines using the same dotnet test commands.
  • Using Docker: If there are Docker configurations provided, follow the corresponding steps in the Dockerfile to build and run tests in containerized environments.
docker build -t opentelemetry-dotnet .
docker run opentelemetry-dotnet dotnet test

Conclusion

By following these steps, you can efficiently set up and run tests for the open-telemetry/opentelemetry-dotnet project.

Source: open-telemetry/opentelemetry-dotnet repository documentation.