Testing
Test automation for Digital Twins
Last updated
Test automation for Digital Twins
Last updated
Based on Unity's test automation framework (more information can be found in the Unity documentation), we have integrated a testing extension for our customers. All test scenes are defined in a scriptable asset, allowing you to extend tests by adding additional scenes as needed.
We provide two standard test tools:
Counting Destroyed MUs on Sinks: Verifies the number of Modular Units (MUs) destroyed on sinks.
Counting MUs Passed on a Sensor: Counts the number of MUs that pass through a sensor.
Please note that physics behavior may vary across different computers, so test results may differ between your machine and our testing environment.
The realvirtual.io test extension allows you to define tests without the need for programming custom scripts or logic.
By default, testing is not enabled as it requires additional Unity packages. To enable testing:
Install Unity Test Framework:
Install Unity Test Framework Version 1.1.33 via the Unity Package Manager.
Set Compiler Define:
Navigate to Project Settings > Player.
Under Scripting Define Symbols, add REALVIRTUAL_TESTS
.
After enabling testing as described above, follow these steps to run and manage your tests:
Open the Test Window:
Select Testing from the realvirtual.io main menu. This will open a new window displaying all defined tests.
View Test Status:
Tests that have passed successfully will be indicated by green buttons.
Tests that have failed will be shown with red buttons, and a message will provide additional information.
Run Tests:
Click the "Run Tests" button to execute all defined tests.
If a test fails, you can select the test button to open the scene associated with the test.
Filter Tests:
You can define filters to narrow down the tests displayed.
When filters are applied, only the filtered tests will be executed when you select "Run Tests".
To define your own tests, follow these steps:
Create a Test Scene List:
In the Unity Project window, right-click in the desired project folder.
Select Create > realvirtual > TestScenes from the context menu.
Default Test Scenes:
The default test scenes provided are located under realvirtual > private > Resources > Testing
.
Add each test scene you wish to include in your testing setup. For each scene listed, ensure the "Run Scene" checkbox is set to true. This setting specifies that the scene should be executed as part of the test process.
The testing window will automatically detect all Test Scene List assets in your project.
To prepare a scene for testing, you need to include a Test Model Controller in each test scene. You can add this controller to your project by using the prefabs located under realvirtual > private > Resources > Testing
.
Test Model Controller
The Test Model Controller manages several test parameters:
Run Test: Determines if the test should be executed.
TimeScale: Adjusts the speed at which the test runs, allowing it to run faster or slower than real time.
Test Time: Specifies the duration of the test in seconds.
Fixed Timestep: Sets the fixed timestep to be used during the test.
You can manually start the test by selecting Run Test (this applies only to the current scene). The Test Model Controller will also call all methods implementing the ITestCheck
interface.
Standard ITestCheck
Implementations
We provide two standard implementations of the ITestCheck
interface:
TestSensorCount: Counts the Modular Units (MUs) passing through sensors where TestSensorCount
is attached. The Test Model Controller automatically checks all TestSensorCount
components in the scene.
TestSinkCount: Counts the MUs destroyed by sinks where TestSinkCount
is attached. The Test Model Controller automatically checks all TestSinkCount
components in the scene.
ITestCheck
To create a custom ITestCheck
implementation, follow these steps:
Create a New MonoBehaviour: Implement the ITestCheck
interface in a new MonoBehaviour script.
Implement the Check
Method: Define the Check
method to return an empty string if the test is successful, or a descriptive message if the test fails.
Here's a sample implementation of a custom ITestCheck
for counting sensor events:
Attach to Component: You can attach this script to any relevant component in your scene.
Automatic Invocation: The Check
method will be called automatically by the Test Model Controller
once the test time is finished.
Success and Failure: Return an empty string for a successful test or a descriptive message if the test fails.
By implementing your own ITestCheck
classes, you can extend the testing capabilities to fit your specific needs.