Testing Strategy
Relevant source files
The following files were used as context for generating this wiki page: - [CONTRIBUTING.md](https://github.com/Treystu/SC/blob/HEAD/CONTRIBUTING.md) - [E2E_IMPLEMENTATION_SUMMARY.md](https://github.com/Treystu/SC/blob/HEAD/E2E_IMPLEMENTATION_SUMMARY.md) - [E2E_TEST_STATUS.md](https://github.com/Treystu/SC/blob/HEAD/E2E_TEST_STATUS.md) - [V1_PRODUCTION_IMPLEMENTATION_PLAN.md](https://github.com/Treystu/SC/blob/HEAD/V1_PRODUCTION_IMPLEMENTATION_PLAN.md) - [V1_READINESS.md](https://github.com/Treystu/SC/blob/HEAD/V1_READINESS.md) - [android/IMPLEMENTATION_SUMMARY.md](https://github.com/Treystu/SC/blob/HEAD/android/IMPLEMENTATION_SUMMARY.md) - [tests/README.md](https://github.com/Treystu/SC/blob/HEAD/tests/README.md) - [tests/e2e/app-basics.e2e.test.ts](https://github.com/Treystu/SC/blob/HEAD/tests/e2e/app-basics.e2e.test.ts) - [tests/scripts/validate-e2e-framework.js](https://github.com/Treystu/SC/blob/HEAD/tests/scripts/validate-e2e-framework.js)The Sovereign Communications project employs a comprehensive, multi-layered testing strategy to ensure code quality, security, and cross-platform consistency for the Web, Android, and iOS applications. The strategy encompasses unit, integration, end-to-end (E2E), performance, mutation, and security testing, all integrated into the CI/CD pipeline. This approach is crucial for validating the shared @sc/core library and ensuring that changes benefit all platforms without introducing regressions.
The testing infrastructure is designed to be robust, covering everything from individual functions to complex, real-world user journeys across multiple devices. Key goals include maintaining high code coverage, especially for critical paths like cryptography, and verifying feature parity across all supported platforms.
Sources: tests/README.md, CONTRIBUTING.md:19-27, 203-221, V1_READINESS.md:200-221
Testing Layers
The project's testing approach is structured in multiple layers, from low-level unit tests to high-level E2E scenarios.
This diagram illustrates the different layers of automated testing employed in the project.
Sources: tests/README.md:7-39
Test Organization
Tests are organized within the monorepo to clearly separate different testing types. Unit tests are co-located with source files, while integration, E2E, and performance tests reside in a dedicated tests/ directory.
This diagram shows the directory structure for tests within the repository.
Sources: tests/README.md:42-67
Test Execution Commands
A set of npm scripts is provided to run the various test suites.
| Command | Description |
|---|---|
npm test | Runs all unit tests. |
npm run test:coverage | Runs unit tests and generates a coverage report. |
npm run test:integration | Runs all integration tests. |
npm run test:e2e | Runs all E2E tests. |
npm run test:e2e:ui | Runs E2E tests in interactive UI mode. |
npm run test:e2e:cross-platform | Runs web-to-web cross-platform E2E tests. |
npm run test:e2e:mobile | Runs all mobile (Android & iOS) E2E tests. |
npm run test:performance | Runs performance benchmarks. |
npm run test:mutation | Runs mutation tests using Stryker. |
Sources: tests/README.md:9-39, CONTRIBUTING.md:68-72
Unit and Integration Testing
Unit and integration tests are built using Jest. Unit tests focus on individual functions and components, while integration tests verify that different parts of the system, such as the crypto and protocol layers, work together correctly.
Key Configuration (jest.integration.config.js)
Integration tests are configured separately from unit tests to manage different setups and execution environments. While the file jest.integration.config.js is referenced, its specific contents are not available in the provided context. However, tests/README.md indicates it is used for integration test configuration.
Coverage Targets
The project enforces strict coverage targets to maintain code quality.
- Overall Coverage: >80% (target is 95%+)
- Critical Paths: 100% (cryptography, authentication, security-sensitive code)
- New Code: 100%
Sources: CONTRIBUTING.md:213-215, tests/README.md:188-191, android/IMPLEMENTATION_SUMMARY.md:123-125
Test Examples
Unit Test Example
// From tests/README.md
import { RateLimiter } from './rate-limiter';
describe('RateLimiter', () => {
it('should allow consumption within capacity', () => {
const limiter = new RateLimiter({
capacity: 10,
refillRate: 1,
});
expect(limiter.tryConsume(5)).toBe(true);
});
});
Sources: tests/README.md:73-85
Integration Test Example
// From tests/README.md
// tests/integration/crypto-protocol.integration.test.ts
describe('Crypto-Protocol Integration', () => {
it('should sign and verify a complete message', async () => {
const identity = await generateIdentity();
const message = createMessage(identity);
const encoded = encodeMessage(message);
const decoded = decodeMessage(encoded);
expect(decoded).toEqual(message);
});
});
Sources: tests/README.md:88-100
End-to-End (E2E) Testing
E2E testing is a critical part of the strategy, designed to validate complete user workflows across all platforms. It uses Playwright for web and Appium for mobile, orchestrated by a custom cross-platform framework.
Sources: E2E_IMPLEMENTATION_SUMMARY.md:5-8
Cross-Platform Test Framework
A unified framework abstracts platform-specific details, allowing tests to be written with a consistent API. The CrossPlatformTestCoordinator manages clients, while WebClient, AndroidClient, and iOSClient implement the platform-specific logic.
This diagram shows the abstraction used for cross-platform E2E testing.
Sources: E2E_IMPLEMENTATION_SUMMARY.md:10-26, tests/scripts/validate-e2e-framework.js:28-33
Web E2E Testing (Playwright)
Web tests are run using Playwright against multiple browsers. The configuration is optimized for CI/CD, capturing traces and videos on failure.
Configuration Highlights (playwright.config.ts)
While the file content is not provided, E2E_IMPLEMENTATION_SUMMARY.md and tests/README.md describe its function:
- Browsers: Tests run on Chromium, Firefox, and WebKit.
- Artifacts: Screenshots and videos are captured on failure.
- CI Integration: Optimized for running in GitHub Actions.
Sources: E2E_IMPLEMENTATION_SUMMARY.md:90-95, tests/README.md:231-234
Web E2E Test Example
// From tests/e2e/app-basics.e2e.test.ts
test('should load the application', async ({ page }) => {
await page.goto('/');
// Check that the page has the correct title
await expect(page).toHaveTitle(/Sovereign Communications/i);
});
Sources: tests/e2e/app-basics.e2e.test.ts:28-34
Mobile E2E Testing (Appium)
Mobile tests use Appium to automate the Android and iOS applications, enabling cross-platform testing between web and mobile devices.
Configuration Highlights (appium.config.ts)
The configuration file sets up drivers and capabilities for both Android and iOS.
| Platform | Automation Name | Default Device |
|---|---|---|
| Android | UiAutomator2 | Android Emulator |
| iOS | XCUITest | iPhone 15 |
The server is configured to run on localhost:4723.
Sources: E2E_IMPLEMENTATION_SUMMARY.md:61-81, tests/scripts/validate-e2e-framework.js:12-16
E2E Testing in CI/CD
E2E tests are integrated into the .github/workflows/e2e.yml pipeline with different jobs for speed and resource management.
This diagram outlines the CI/CD workflow for E2E tests.
Sources: E2E_IMPLEMENTATION_SUMMARY.md:86-113, E2E_TEST_STATUS.md:120-131
Mutation Testing (Stryker)
Mutation testing is used to assess the quality of the tests themselves. It introduces small changes (mutations) into the source code and checks if the test suite can detect them.
Configuration Highlights (stryker.config.js)
The configuration for Stryker is defined in stryker.config.js. While its contents are not provided, tests/README.md confirms its existence and purpose for mutation testing configuration.
Sources: tests/README.md:36-39, 175
Other Testing
The strategy also includes several other important testing types:
- Property-Based Testing: Uses
fast-checkto test properties that should hold true for a wide range of generated inputs, which is especially useful for validating cryptographic functions. - Performance Testing: A dedicated suite (
npm run test:performance) exists to run benchmarks and measure key performance metrics like latency and throughput. - Security Audits: Manual and automated security reviews are part of the V1.0 rollout plan, including penetration testing and vulnerability scanning.
Sources: tests/README.md:129-145, 30-32, V1_PRODUCTION_IMPLEMENTATION_PLAN.md:462-470
Summary
The testing strategy for Sovereign Communications is a mature, multi-faceted system designed to ensure the reliability, security, and performance of a complex, cross-platform application. By combining automated unit, integration, and E2E tests with specialized checks like mutation and property-based testing, the project aims to maintain a high standard of quality. The CI/CD integration ensures that these checks are performed continuously, providing rapid feedback to developers and safeguarding the production release.