FRC1076 / FRC1076/2026-FirstYearRobot

[Research] Automate Logic Testing for the Indexer State Machine

Open
#2 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
0
Forks
0
PR merge metrics
No merged PRs in 30d

Description

**Objective:** Write our first 'Headless' Unit Test to ensure the Indexer (feeder) stops automatically when it senses a ball.

**Why this matters:**
It’s easy to accidentally break logic when changing code. A unit test acts as a 'safety net' that runs in 2 seconds on your laptop and tells you exactly what broke.

**Best Practice Recommendation (State Machine Testing):**
Don't just test if a motor moves. Test the **Logic**.
* *Scenario:* If the Indexer is `INTAKING` and the `ballSensor` becomes `true`, the state should change to `LOADED` and the motor should stop.

**The Prototype Goal:**
1. **Setup the Test Folder:** Create `src/test/java/frc/robot/subsystems/fuel/` and a new file `FuelSubsystemTest.java`.
2. **Use JUnit 5:** Use the `@Test` annotation.
3. **Write the 'Stop on Sensor' Test:**
* **Arrange:** Set the subsystem to 'Intake' mode.
* **Act:** Use `DigitalInputSim` to 'fake' the ball sensor being triggered.
* **Assert:** Check `indexer.get()` to ensure it is now `0.0`.
4. **Run it:** Use `./gradlew test` in the terminal.

**Resources:**
* [WPILib Unit Testing Guide](https://docs.wpilib.org/en/stable/docs/software/wpilib-tools/robot-simulation/unit-testing.html)
* [The 'Arrange-Act-Assert' Pattern](https://automationpanda.com/2020/07/07/arrange-act-assert-a-pattern-for-writing-good-tests/)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.