This PR introduces the necessary changes to build.gradle and other files to support unit testing.
The testing framework utilized is TestNG with mocking from Mockito.
Running tests can be performed via the test Gradle task or via in code VSCode buttons (modifications to settings.json are required for VSCode tests to get necessary dependencies, though the Gradle tests will still run without them). The Java Test Runner extension is added as a recommended extension (via extensions.json) for ease of use.
The tests have also been added to the GitHub Action which performs build and lint checks during pushes to and pull requests targetted at master.
Provided is a sample unit test for the XboxController class:
XboxController.java is modified to be a true Singleton and allow for testability (accepting a Factory to create the internal controller such that it can be mocked)
Some minor refactoring to XboxController.java to reduce code repetition.
RobotContainer.java is modified to use the new Singleton form of XboxController.java (other changes are just linting)
Test currently covers the deadzone calculations for left and right joysticks.
Future Work:
Provide a sample for how to do functional testing with the FRC simulator (presuming this is feasible).
Configure Gradle to run unit tests or functional tests separately if requested.
One known limitation:
Due to a known bug with the VSCode Java Test Runner extension, tests using the TestNG DataProvider (as is done with this example) don't show as failed unless the final data point fails. The tests will still fail properly with Gradle, thus this does not affect any of the automated checks.
This PR introduces the necessary changes to
build.gradle
and other files to support unit testing. The testing framework utilized is TestNG with mocking from Mockito.Running tests can be performed via the
test
Gradle task or via in code VSCode buttons (modifications tosettings.json
are required for VSCode tests to get necessary dependencies, though the Gradle tests will still run without them). TheJava Test Runner
extension is added as a recommended extension (viaextensions.json
) for ease of use.The tests have also been added to the GitHub Action which performs build and lint checks during pushes to and pull requests targetted at
master
.Provided is a sample unit test for the
XboxController
class:XboxController.java
is modified to be a true Singleton and allow for testability (accepting a Factory to create the internal controller such that it can be mocked)XboxController.java
to reduce code repetition.RobotContainer.java
is modified to use the new Singleton form ofXboxController.java
(other changes are just linting)Future Work:
One known limitation: Due to a known bug with the VSCode
Java Test Runner
extension, tests using the TestNGDataProvider
(as is done with this example) don't show as failed unless the final data point fails. The tests will still fail properly with Gradle, thus this does not affect any of the automated checks.