Show argument values after passing Mockito unit tests

Here’s a small snippet of code:

      @Test
      @Order(5)
      @DisplayName("Test if robot can turn left using PID drive")
      public void turningLeft() {
        // Hardcode NAVX sensor return value for angle
        when(m_navx.getAngle()).thenReturn(0.0);

        // Try to turn left
        m_driveSubsystem.teleopPID(0.0, -1.0, 1);

        // Verify that left and right motors are being driven with expected values
        verify(m_lMasterMotor, times(1)).set(ArgumentMatchers.eq(ControlMode.PercentOutput), AdditionalMatchers.eq(0.0, DELTA), 
                                              ArgumentMatchers.eq(DemandType.ArbitraryFeedForward), AdditionalMatchers.gt(0.0));
        verify(m_rMasterMotor, times(1)).set(ArgumentMatchers.eq(ControlMode.PercentOutput), AdditionalMatchers.eq(0.0, DELTA), 
                                              ArgumentMatchers.eq(DemandType.ArbitraryFeedForward), AdditionalMatchers.lt(0.0));
      }

What I want to see is the arguments that were passed into m_lMasterMotor.set() and m_rMasterMotor.set() when they pass the unit test. Right now, I can only see the values when I temporarily purposely change the test to make it fail, and then VSCode shows me the actual argument values vs my expected ones.

Have your mock emit a print statement when the method is called; generally, successful tests are assumed to be quiet for good reason, though.

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.