KentridgeRobotics / 2021Robot

Other
0 stars 7 forks source link

Add Testing Infrastructure and an Example Test Class #2

Closed skallaher closed 3 years ago

skallaher commented 3 years ago

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:

Future Work:

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.