Skip to content

Best practices for mocking dependencies? #34

@christianheussy

Description

@christianheussy

I'm really enjoying statig but am facing challenges with unit testing state transitions. My goal is to:

  1. Initialize the state machine to a specific state.
  2. Mock dependencies within the state machine.
  3. Verify state transitions after handling events.

I'm using serde for state initialization (as suggested in #25), but this prevents me from setting mock expectations beforehand. See a reproducible example here: #33.

The issue is that neither UninitializedStateMachine<M> nor InitializedStateMachine<M> implement core::ops::DerefMut, preventing mutable access for mock configuration before initialization.

A potential solution is implementing DerefMut (#32), but I'm unsure if providing mutable access at all times is ideal. Perhaps implementing it only for UninitializedStateMachine<M> would be better? I'm open to suggestions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions