Duncan Tourolle 3604e8f7a0
Some checks failed
🏗️ Build Plugin / build (pull_request) Failing after 9s
🧪 Test Plugin / test (pull_request) Failing after 9s
Add unit.tests
2025-11-14 22:13:24 +01:00

3.8 KiB

SRF Play Plugin Tests

This directory contains the test suite for the Jellyfin SRF Play plugin.

Test Structure

Unit Tests (UnitTests/)

Fast, isolated tests that verify individual components without external dependencies.

  • StreamUrlResolverTests.cs - Tests for stream URL resolution logic
  • MetadataCacheTests.cs - Tests for metadata caching functionality

Integration Tests (IntegrationTests/)

Tests that make real API calls to validate the SRF Play API spec compliance.

  • SRFApiSpecTests.cs - Validates API endpoints, response schemas, and data integrity

Legacy Tests

  • Program.cs - Legacy console test application (kept for manual testing)
  • TestPlayV3Api.cs - Legacy Play v3 API tests (kept for manual testing)

Running Tests

Run All Tests

dotnet test

Run Only Unit Tests

dotnet test --filter "Category!=Integration&Category!=APISpec"

Run Only Integration Tests

dotnet test --filter "Category=Integration"

Run Only API Spec Tests

dotnet test --filter "Category=APISpec"

Run Tests with Coverage

dotnet test --collect:"XPlat Code Coverage"

Run Tests with Detailed Output

dotnet test --logger "console;verbosity=detailed"

Test Categories

Tests are organized using xUnit traits:

  • Unit Tests: No category (default)
  • Integration Tests: [Trait("Category", "Integration")]
  • API Spec Tests: [Trait("Category", "APISpec")]

Continuous Integration

Unit Tests

  • Run on every push and pull request
  • Workflow: .github/workflows/unit-tests.yaml
  • Must pass before merging PRs

API Spec Tests (Nightly)

  • Run every night at 2 AM UTC
  • Workflow: .github/workflows/nightly-api-tests.yaml
  • Validates that the SRF Play API is still working as expected
  • Creates an issue automatically if tests fail

Adding New Tests

Unit Test Example

using Xunit;
using FluentAssertions;

public class MyServiceTests
{
    [Fact]
    public void MyMethod_WithValidInput_ReturnsExpectedResult()
    {
        // Arrange
        var service = new MyService();

        // Act
        var result = service.MyMethod("test");

        // Assert
        result.Should().Be("expected");
    }
}

Integration Test Example

using Xunit;
using FluentAssertions;

[Trait("Category", "Integration")]
public class MyApiTests
{
    [Fact]
    public async Task ApiCall_ReturnsValidData()
    {
        // Arrange
        var client = new ApiClient();

        // Act
        var result = await client.GetDataAsync();

        // Assert
        result.Should().NotBeNull();
    }
}

Test Dependencies

  • xUnit - Test framework
  • FluentAssertions - Fluent assertion library for readable tests
  • Moq - Mocking framework for creating test doubles
  • Microsoft.NET.Test.Sdk - .NET test SDK

Best Practices

  1. Unit Tests Should Be Fast: Each test should run in milliseconds
  2. Integration Tests Can Be Slower: API calls may take seconds
  3. Use Descriptive Names: Test names should describe what they test
  4. Follow AAA Pattern: Arrange, Act, Assert
  5. One Assertion Per Test: Focus each test on a single behavior
  6. Clean Up Resources: Implement IDisposable when needed
  7. Avoid Test Interdependence: Each test should be independent

Troubleshooting

Tests Fail Locally

  1. Ensure you have internet connectivity (integration tests need it)
  2. Check if the SRF Play API is accessible from your location
  3. Verify .NET 8.0 SDK is installed

API Spec Tests Fail

  1. Check if the SRF Play API has changed
  2. Review the API documentation
  3. Update models and tests if necessary

Coverage is Low

  1. Add tests for uncovered code paths
  2. Use dotnet test --collect:"XPlat Code Coverage" to generate reports
  3. Review TestResults/ directory for coverage details