Skip to content

Latest commit

 

History

History
158 lines (105 loc) · 4.65 KB

TESTING.md

File metadata and controls

158 lines (105 loc) · 4.65 KB

Testing Guidelines

This document outlines the testing process for the Telware Cross-Platform project. Proper testing ensures that our application is reliable, performant, and free of critical bugs. Follow these guidelines to maintain high standards across all features.

Table of Contents

  1. Overview
  2. Testing Setup
  3. Testing Types
  4. Writing Tests
  5. Running Tests
  6. Debugging and Troubleshooting
  7. Referencing Documentation

Overview

Testing is a critical part of the development workflow. All code changes must include tests, and the tests must pass before merging into the develop branch. The testing strategy ensures compatibility across platforms and helps identify regressions early in the development process.

For more details on the development workflow, refer to:


Testing Setup

Before running or writing tests, ensure your environment is properly configured:

Prerequisites

  1. Flutter SDK: Install the latest version (Setup Guide).
  2. Dart SDK: Included with the Flutter installation.
  3. Emulators/Devices:
    • Set up Android emulators and/or iOS simulators for integration tests.

Installing Dependencies

Run the following command to install required testing dependencies:

flutter pub get

Testing Types

We use multiple levels of testing to ensure application quality:

  1. Unit Tests:

    • Validate individual functions, classes, or methods.
    • Example: Testing a utility function in lib/utils/.
  2. Widget Tests:

    • Verify the behavior and layout of individual widgets.
    • Example: Ensuring the LoginButton component renders correctly and triggers actions as expected.
  3. Integration Tests:

    • Test the application as a whole, including interactions between components and backend services.
    • Example: Validating the complete login process with API calls.

Writing Tests

Tests are stored in the test/ directory. Use the following structure to organize your tests:

test/
├── core/              # Unit tests
├── features/            # Widget tests
└── integration/       # Integration tests

Guidelines for Writing Tests

  1. Follow Coding Standards:

  2. Use Descriptive Test Names:

    • Example: test("should return a valid user object on successful login", () { ... });
  3. Mock Dependencies:

    • Use libraries like mockito to mock services or APIs during tests.
  4. Focus on Edge Cases:

    • Test not just typical scenarios but also edge cases (e.g., network failures, invalid inputs).

Running Tests

Use the following commands to execute tests:

Running Unit and Widget Tests

To run all unit and widget tests:

flutter test

Running a Specific Test File

To run tests in a specific file:

flutter test test/unit/sample_test.dart

Running Integration Tests

Integration tests require a connected device or emulator. Start the tests with:

flutter drive --target=test_driver/app.dart

Debugging and Troubleshooting

Common Issues

  1. Test Fails Unexpectedly:

    • Review error logs and ensure the latest dependencies are installed:
    flutter pub get
    
  2. Integration Test Fails on Emulator:

    • Confirm the emulator or device is running and has sufficient resources.
    • Restart the emulator if needed.
  3. Flaky Tests:

    • If a test passes intermittently, check for race conditions or dependency issues.

Tools for Debugging

  • Flutter DevTools: Use:
flutter pub global activate devtools

to install and run Flutter's debugging tools.

  • Logs and Stack Traces: Check detailed logs for root cause analysis.

Referencing Documentation

For a seamless testing experience, leverage the following documents:

  • README.md: High-level overview of the testing process.
  • PROJECT_FLOW.md: Insights into the development lifecycle, including testing stages.
  • CODING_GUIDELINES.md: Best practices for writing clean and maintainable test code.

By adhering to these guidelines, we can ensure the stability and quality of the Telware Cross-Platform application across all platforms and devices. If you encounter issues or need assistance, raise a query in the project Slack channel or file an issue in the repository.