zarfld / LinuxCnc_PokeysLibComp

Pokeys comp for LinuxCnc using https://bitbucket.org/mbosnak/pokeyslib.git
MIT License
5 stars 0 forks source link

Implement Mocking and Unit Tests for PoKeysLib Integration Without Hardware #57

Open zarfld opened 1 day ago

zarfld commented 1 day ago

Issue: Implement Mocking and Unit Tests for PoKeysLib Integration Without Hardware

Description

To ensure continuous integration and testing of the PoKeysLib integration in the LinuxCNC system without requiring physical PoKeys hardware, we need to implement mocking and simulation strategies for hardware components. This will allow us to run tests on CI platforms such as GitHub Actions, ensuring that critical parts of the system can be validated without direct access to the hardware.

Tasks

  1. Mock Hardware Interfaces:

    • Implement mock objects for the PoKeysLib device interactions such as digital I/O, analog I/O, counters, and PWM.
    • Ensure that mock objects replicate the behavior of actual PoKeys devices and provide expected values or simulate edge cases (e.g., hardware failure, timeouts).
  2. Dependency Injection for Device Interface:

    • Refactor code to allow dependency injection for the hardware interface.
    • Enable the swapping of real PoKeys hardware with mocks or simulators for testing purposes.
  3. Simulator for Complex Device Behaviors:

    • Create a simulator class that mimics more complex PoKeys device interactions.
    • This should simulate real-time updates, axis movements, homing sequences, etc., allowing more detailed testing of motion control.
  4. CI Testing Configuration:

    • Configure GitHub Actions to run the test suite with mocks and simulators in place of real hardware.
    • Implement environment checks to switch between real hardware (for local testing) and mock objects (for CI testing).
  5. Add Unit Tests for PoKeys Integration:

    • Add unit tests that verify the interaction between the application logic and the mocked PoKeys device.
    • Ensure coverage for key features like digital I/O state changes, axis position feedback, homing, and error conditions.
  6. Update Documentation:

    • Provide documentation on how to run tests locally with real hardware versus how to run tests in the CI environment using mocks/simulators.
    • Include instructions for setting environment variables to toggle between real and mock devices.

Benefits

Resources

Acceptance Criteria