# Testing Guide for splash_video

This package includes comprehensive unit and integration tests to ensure reliability and correctness.

## Test Structure

### Unit Tests (`/test`)

Unit tests verify individual components in isolation:

- **video_source_test.dart** - Tests for all Source types (Asset, Network, DeviceFile, Bytes)
- **splash_video_controller_test.dart** - Tests for controller lifecycle and operations
- **video_config_test.dart** - Tests for VideoConfig and VisibilityEnum
- **utils_test.dart** - Tests for utility functions, exceptions, and typedefs
- **splash_video_page_test.dart** - Widget tests for SplashVideoPage

### Integration Tests (`/example/integration_test`)

Integration tests verify end-to-end functionality:

- **plugin_integration_test.dart** - Full integration tests including:
  - Configuration validation
  - Error handling
  - Overlay rendering
  - Controller integration
  - Source type handling
  - VideoConfig integration

## Running Tests

### Run All Unit Tests

```bash
flutter test
```

### Run Specific Test File

```bash
flutter test test/video_source_test.dart
```

### Run Tests with Coverage

```bash
flutter test --coverage
```

### Run Integration Tests

```bash
cd example
flutter test integration_test/plugin_integration_test.dart
```

### Run Integration Tests on Device

```bash
cd example
flutter drive \
  --driver=test_driver/integration_test.dart \
  --target=integration_test/plugin_integration_test.dart
```

## Test Coverage

The test suite covers:

- ✅ All Source types and validation
- ✅ SplashVideoController lifecycle
- ✅ VideoConfig options
- ✅ Error handling and callbacks
- ✅ Overlay rendering
- ✅ Navigation validation
- ✅ Looping behavior
- ✅ Widget composition

## Writing New Tests

### Unit Test Template

```dart
import 'package:flutter_test/flutter_test.dart';
import 'package:splash_video/splash_video.dart';

void main() {
  group('Feature Name', () {
    test('should do something', () {
      // Arrange
      final input = ...;
      
      // Act
      final result = ...;
      
      // Assert
      expect(result, equals(expected));
    });
  });
}
```

### Widget Test Template

```dart
testWidgets('widget should render', (WidgetTester tester) async {
  await tester.pumpWidget(
    MaterialApp(
      home: YourWidget(),
    ),
  );
  
  expect(find.byType(YourWidget), findsOneWidget);
});
```

### Integration Test Template

```dart
testWidgets('integration scenario', (WidgetTester tester) async {
  IntegrationTestWidgetsFlutterBinding.ensureInitialized();
  
  await tester.pumpWidget(MyApp());
  await tester.pumpAndSettle();
  
  // Interact with the app
  await tester.tap(find.byIcon(Icons.add));
  await tester.pumpAndSettle();
  
  // Verify results
  expect(find.text('Result'), findsOneWidget);
});
```

## CI/CD Integration

### GitHub Actions

```yaml
name: Tests
on: [push, pull_request]

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: subosito/flutter-action@v2
      - run: flutter pub get
      - run: flutter test --coverage
      - run: cd example && flutter test integration_test
```

## Troubleshooting

### MediaKit Initialization

Some tests require MediaKit initialization. This is handled automatically in test files:

```dart
setUpAll(() {
  MediaKit.ensureInitialized();
});
```

### Video Assets

Integration tests may require actual video assets in `example/assets/`. For tests without real videos, use error handling:

```dart
onVideoError: (_) {}, // Suppress errors in tests
```

### Platform Differences

Some media_kit features are platform-specific. Tests should be designed to handle platform variations gracefully.

## Test Best Practices

1. **Keep tests isolated** - Each test should be independent
2. **Use descriptive names** - Test names should explain what they verify
3. **Test edge cases** - Include boundary conditions and error scenarios
4. **Mock external dependencies** - Use test doubles when appropriate
5. **Clean up resources** - Dispose controllers and players in tearDown
6. **Use test groups** - Organize related tests together
7. **Verify error handling** - Test both success and failure paths

## Known Limitations

- Video playback tests require platform-specific media support
- Some tests may need real video files to fully verify behavior
- Network tests depend on connectivity (should use mocks for CI/CD)
- Player initialization timing can vary across platforms
