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 logicMetadataCacheTests.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
- Unit Tests Should Be Fast: Each test should run in milliseconds
- Integration Tests Can Be Slower: API calls may take seconds
- Use Descriptive Names: Test names should describe what they test
- Follow AAA Pattern: Arrange, Act, Assert
- One Assertion Per Test: Focus each test on a single behavior
- Clean Up Resources: Implement
IDisposablewhen needed - Avoid Test Interdependence: Each test should be independent
Troubleshooting
Tests Fail Locally
- Ensure you have internet connectivity (integration tests need it)
- Check if the SRF Play API is accessible from your location
- Verify .NET 8.0 SDK is installed
API Spec Tests Fail
- Check if the SRF Play API has changed
- Review the API documentation
- Update models and tests if necessary
Coverage is Low
- Add tests for uncovered code paths
- Use
dotnet test --collect:"XPlat Code Coverage"to generate reports - Review
TestResults/directory for coverage details