realvirtual.io
  • Building Digital Twins with Unity and realvirtual.io
  • Basics
    • Installation
    • Demo Model
      • Old Demo Model
    • Editor User Interface
      • Hierarchy Window
      • 3D Views
      • Quick Edit
      • Move Pivot Points (Pro)
      • Selection Window (Pro)
      • Material Window (Pro)
      • Measurement (Pro)
      • Kinematic Tool (Pro)
      • Model Checker
    • Runtime UI
      • Group Manager
      • Debug Console
      • Responsiveness
      • Runtime Persistence
    • Importing and exporting
    • Folder structure
    • Tutorial
    • Physics
    • CAD import (Pro)
      • CADLink (Pro)
      • CAD Checker (Pro)
      • CAD Updater (Pro)
    • Reusable Components (Prefabs)
    • Cadenas parts4cad
    • Publishing the Digital Twin
    • Revision management
  • News
  • Login & Download Updates (Pro)
  • Components & Scripts
    • Realvirtual
      • Environment Controller
    • MU, Source and Sink
      • Source
      • Sink
    • Motion and Kinematic
      • Drive
      • Kinematic
      • Group
      • Joint
      • CAM
      • TransportSurface
      • Guided Transport
      • Drive behavior
      • Chain
      • Chain element
      • Motion for developers
    • Sensors
      • Sensor
      • Measure
      • MeasureRaycast
    • Picking and Placing MUs
      • Grip
      • Gripper
      • Fixer
      • Pattern
    • Changing MUs
      • MaterialChanger
      • PartChanger
      • Cutter
    • Scene Interaction
      • 3D Buttons
      • Screen Overlay Buttons
      • Scene Selectables
      • Lamp
      • Interact3D
      • UI components
      • HMI components (Pro)
        • Start your own HMI
        • HMI Tab
        • HMI DropDown
        • HMI Puschbutton
        • HMI Switch
        • HMI Value
        • HMI Text
        • HMI Slider
        • HMI Message
        • HMI Marker
      • ModelZoo (Pro)
    • Interfaces
      • Interface Tools
        • Signal Manager
        • Signal Importer Exporter
        • Signal Catcher
        • OnValueChangedReconnect
      • Signal Importer / Exporter
      • ABB RobotStudio (Pro)
      • Denso Robotics (Pro)
      • EthernetIP (Pro)
      • Fanuc (Pro)
      • FMI
      • Igus Rebel
      • MQTT (Pro)
      • Modbus (Pro)
      • OPCUA (Pro)
      • PLCSIM Advanced (Pro)
      • RoboDK (Pro)
      • RFSuite (Pro)
      • SEW SimInterface (Pro)
      • Siemens Simit Interface (Pro)
      • Simit Shared Memory (Pro)
      • Simulink (Pro)
      • S7 TCP
      • TwinCAT (Pro)
      • TwinCAT HMI (Pro)
      • UDP (Pro)
      • Universal Robots (Pro)
      • Wandelbots Nova (Pro)
      • Websocket (Pro)
      • Windmod Y200 (Pro)
      • Custom Interfaces
    • Performance Tools
      • Combine Meshes (Pro)
      • Create Prefab (Pro)
      • Hierarchy Cleanup (Pro)
      • Mesh Optimizer (Pro)
      • Performance Optimizer (Pro)
    • Defining Logic
      • Unity Scripting
      • Behavior Graph
      • Logicsteps
      • Unity Visual Scripting
      • Recorder
    • Robot Inverse Kinematics (Pro)
    • Volume Tracking (Pro)
  • Multiplayer (Pro)
  • Extensions
    • ModelZoo
      • Beckhoff TwinCAT
      • Siemens S7
      • Denso Cobotta 1300
      • Wandelbots Nova Fanuc CRX
      • Universal Robots UR10
      • Fanuc Roboguide
    • realvirtual.io AIBuilder
      • realvirtual.io AI Builder Overview
      • Generate AI Training Data
      • AI Training
      • Testing AI in a Digital Twin
      • Deploying the AI
    • realvirtual.io Simulation
      • Conveyor Library
      • Path System
        • Path finding
        • Line
        • Curve
        • Workstation
        • Catcher
        • Pathmover
    • realvirtual.io Industrial Metaverse
      • Setup Guide
      • VR Modules
      • AR Modules
      • Multiuser
    • AGX Physics
    • VR Builder
    • CMC ViewR
  • Advanced Topics
    • Render Pipelines
    • Mixed Reality with Meta Quest3
    • Upgrade Guide
      • Upgrade to 2022
    • Open Digital Twin Interface
    • Usefull Addons
    • Improving Performance
    • Supported Platforms
    • Compiler Defines
    • For Developers
      • Important Classes and Interfaces
      • Assembly Definitions
      • Starting your development
      • Class documentation
      • realvirtual Init Sequence
      • realvirtualBehavior Lifetime Methods
      • Testing
    • Newtonsoft JSON
    • Troubleshooting
  • Release Notes
  • AI Digital Twin Assistant (GPT4)
  • License Conditions
Powered by GitBook
On this page
  • Prerequisites
  • Test window
  • Defining your own tests
  • Preparing a Scene for Tests
  • Implementing Your Own ITestCheck
Edit on GitHub
  1. Advanced Topics
  2. For Developers

Testing

Test automation for Digital Twins

PreviousrealvirtualBehavior Lifetime MethodsNextNewtonsoft JSON

Last updated 9 months ago

Based on Unity's test automation framework (more information can be found in the ), 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:

  1. Counting Destroyed MUs on Sinks: Verifies the number of Modular Units (MUs) destroyed on sinks.

  2. 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.

Prerequisites

By default, testing is not enabled as it requires additional Unity packages. To enable testing:

  1. Install Unity Test Framework:

    • Install Unity Test Framework Version 1.1.33 via the Unity Package Manager.

  2. Set Compiler Define:

    • Navigate to Project Settings > Player.

    • Under Scripting Define Symbols, add REALVIRTUAL_TESTS.

Test window

After enabling testing as described above, follow these steps to run and manage your tests:

  1. Open the Test Window:

    • Select Testing from the realvirtual.io main menu. This will open a new window displaying all defined tests.

  2. 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.

  3. 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.

  4. 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".

Defining your own tests

To define your own tests, follow these steps:

  1. 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.

  2. 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.

Preparing a Scene for Tests

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.

Implementing Your Own ITestCheck

To create a custom ITestCheck implementation, follow these steps:

  1. Create a New MonoBehaviour: Implement the ITestCheck interface in a new MonoBehaviour script.

  2. 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:

namespace realvirtual
{
    using NaughtyAttributes;
    using UnityEngine;

    public class TestSensorCount : MonoBehaviour, ITestCheck
    {
        [InfoBox("This is just for internal realvirtual.io Development and Test automation", EInfoBoxType.Warning)]
        public int DueSensorCount;  // Expected count of MUs passing the sensor

        public int Tolerance = 0;  // Allowed tolerance in the count

        public string Check()
        {
            // Get the current count of MUs passing the sensor
            var counter = GetComponent<Sensor>().Counter;
            
            // Calculate the difference between the expected and actual count
            int difference = Mathf.Abs(counter - DueSensorCount);

            // Check if the count is within the allowed tolerance
            if (difference <= Tolerance)
            {
                return "";  // Test passed
            }
            else
            {
                // Return a descriptive failure message
                if (Tolerance == 0)
                    return "Sensor count at " + this.name + " is " + counter + " but should be " + DueSensorCount;
                else
                    return "Sensor count at " + this.name + " is " + counter + " but should be within " + Tolerance + " of " + DueSensorCount;
            }
        }
    }
}

Key Points

  • 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.

Unity documentation
Installing Unity Test Framework via Unity Package Manager
Enable testing in the Project Settings
Testing window with successfull tests
Test window with failures
Standard test scenes