Tests that come with pyfrc¶
pyfrc’s testing functionality has not yet been updated to work with RobotPy 2020
pyfrc comes with testing functions that can be used to test basic functionality of just about any robot, including running through a simulated practice match.
These generic test modules can be applied to
wpilib.SampleRobot based robots.
The primary purpose of these tests is to run through your code and make sure that it doesn’t crash. If you actually want to test your code, you need to write your own custom tests to tease out the edge cases.
To use these, add the following to a python file in your tests directory:
from pyfrc.tests import *
test_autonomous(control, fake_time, robot, gamedata)¶
Runs autonomous mode by itself
test_disabled(control, fake_time, robot)¶
Runs disabled mode by itself
test_operator_control(control, fake_time, robot)¶
Runs operator control mode by itself
test_practice(control, fake_time, robot)¶
Runs through the entire span of a practice match
The purpose of the fuzz ‘test’ is not exactly to ‘do’ anything, but rather it mashes the buttons and switches in various completely random ways to try and find any possible control situations and such that would probably never normally come up, but.. well, given a bit of bad luck, could totally happen.
Keep in mind that the results will totally different every time you run this, so if you find an error, fix it – but don’t expect that you’ll be able to duplicate it with this test. Instead, you should design a specific test that can trigger the bug, to ensure that you actually fixed it.
test_fuzz(hal_data, control, fake_time, robot)¶
Runs through a whole game randomly setting components
Returns true if the object can be ignored
The purpose of this test is to ensure that all of your robot code has docstrings. Properly using docstrings will make your code more maintainable and look more professional.