About a year ago, I teased a user interface for a Unit Testing plugin. For many reasons, that version of the plugin was never released. After releasing Nexus Plugin Framework, I started work on a new Unit Testing plugin to release a fully polished Unit Testing plugin for Roblox development.
Why Unit Test
Most developers on the Roblox platform use manual testing for developing systems. While this works for most games, manual testing is a long and fault-prone activity that still leads to major bugs reaching players. Unit testing provides a fast and consistent way to test the logic of games, plugins, and subsystems for cases that could come up in production, both as common cases and edge cases.
How to Write Unit Tests
Writing unit tests for Nexus Unit Testing and TestEZ is described in the docs for both projects:
- Nexus Unit Testing: https://thenexusavenger.github.io/Nexus-Unit-Testing/getting-started/writing-tests/
- TestEZ: https://roblox.github.io/testez/getting-started/writing-tests/
For the broader topic of “how to write unit tests”, this thread does not cover practices for creating unit tests. At a super high level, you should focus on:
- “Edge coverage”: Test cases that hit specific logic (ex: the if and else conditions are ran).
- “Branch coverage”: Test cases that reach logic (ex: all cases that determines how an if statement is evaluated is ran)
- “Path coverage”: Test cases that cover all possible branches through all possible edges.
Major Features of the Plugin
- Side buttons for running all tests, only failed tests, or only selected tests.
- Output window that can support very long outputs from tests.
- Nesting tests.
- TestEZ support.
- Plugin actions for allowing shortcuts.
- Theme support, even without restarting Roblox Studio.
The reason this is in Cool Creations instead of Community Resources is because the plugin is not free right now. The plugin is currently 500 Robux ($6.25 based on buying Robux, $1.75 based on DevEx) to offset the time investment for creating the plugin. After 1 month without a significant update, the plugin will be made free (currently March 26th). For those who don’t want to pay, the plugin can be imported into Roblox Studio using Rojo using the GitHub repository.
Update: This plugin has been made free.
The current design does have some limitations that should be known going in. For bugs, see the README in the GitHub repository.
- When rerunning test cases, the
ModuleScriptis rerun with all tests. This may change in the future since it doesn’t require that much in terms of changes.
- When running TestEZ, all test cases are reported after running the tests. Allowing them to appear as they were running would require re-implementing TestEZ and would make updates harder to perform.
- While displaying a long output is efficient, displaying a lot of tests is not. This may be implemented at a future time into Nexus Plugin Framework, but it would be a big feature to implement.
- Some tests require a running session. Running tests does not automatically do it and you should skip the test if a running game is not detected.
- If you require a
ModuleScriptonce outside of a test case using Nexus Unit Testing (not TestEZ), the output will appear in the root test instead of the test case that is calling methods. This is because the environment is determined when requiring. To get around this, you should require the module in each test if using Nexus Unit Testing. TestEZ does not have a workaround since the test cases are just displayed after running rather than capturing the output.