Enfusion Script API
Loading...
Searching...
No Matches
Script Testing Framework

Classes

interface  Test
 Attribute used for tests annotation and assignment to Suites. More...
 
interface  Step
 Attribute which marks a method as part of the testing process. More...
 
interface  TestHarness
 Collection and main interface of the Testing framework. More...
 
interface  TestSuite
 Collection of tests. More...
 
interface  TestBase
 Test base class. More...
 
interface  TestResultBase
 Base class for test results. More...
 

Enumerations

enum  EStage { EStage.Setup , EStage.Main , EStage.TearDown }
 Stage definition used in conjunction with Step attribute. More...
 

Detailed Description

Script Testing Framework

Introduction

  • Provides a unified and simple interface that emphasizes the smallest amount of boiler plate code possible.
  • The collection and instantiation of its primitives is performed right after the script compilation.
  • Within the framework a SINGLE test harness derived class can exist. The harness runs the tests and contains API to access them.
  • The test units are compiled to Suites. These provide additional API for environmental control.

Simple tests

Can be perfomed in form of annotated free functions.

Note: Notice the Suite name in the attribute.

[Test("MyFirstTestSuite")]
TestResultBase MyFooBarTest() { return TestBoolResult(5 > 3); }
Base class for test results.
Definition TestingFramework.c:198
Attribute used for tests annotation and assignment to Suites.
Definition TestingFramework.c:97

Stateful tests

More elaborate tests that need some state and will run for several ticks have to be defined as TestBase derived classes. Your logic has to be ran through step methods.

Step methods

  • You can name your step methods however you like.
  • They have to be annotated by the [Step(Stage)] attribute which pairs the step with a stage.

Stages

  • They divide the steps into groups that express the initialization and finalization process.
  • Stages are executed in order Setup -> Main -> TearDown.
  • Methods in stages are executed in order of definition.

Return values

  • void -> Will get executed only once.
  • bool -> Will get executed every tick until true is returned.

Result

  • Result is set via API member method of TestBase SetResult(TestResultBase).
  • Setting a result which evaluates to failure will terminate the stage.

Failure unwind

  • If the Setup stage fails the test only terminates and TearDown is not called.
  • Main stage failure will trigger the TearDown.
  • TearDown failure will do nothing.

Timeout

  • The tests won't timeout by default. The value may be specified via Test attribute.
  • The timeout counter resets for every stage method.
  • If the stage method times out the TimeoutResult is set (it evaluates to failure and the failure unwind process starts).
[Test("MyFirstTestSuite", timeoutS: 2, timeoutMs: 250)]
class MyAsyncTest : TestBase
{
// Simple blocking initialization.
[Step(EStage.Setup)]
void Initialize() { ... }
// Async test which is waiting for result for several frames.
[Step(EStage.Main)]
bool Pool() { ... }
// Finalization process waiting for result for several frames.
[Step(EStage.TearDown)]
bool FinalizeA() { ... }
// Simple blocking finalization call.
[Step(EStage.TearDown)]
void FinalizeB() { ... }
}
EStage
Stage definition used in conjunction with Step attribute.
Definition TestingFramework.c:115
Attribute which marks a method as part of the testing process.
Definition TestingFramework.c:124
Test base class.
Definition TestingFramework.c:178

Enumeration Type Documentation

◆ EStage

enum EStage

Stage definition used in conjunction with Step attribute.

Enumerator
Setup 
Main 
TearDown