Script Testing Framework
\page Page_System_ScriptTestingFramework Script Testing Framework \tableofcontents
\section Introduction 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.
\section SimpleTests Simple tests
Can be perfomed in form of annotated <b>free functions</b>.
<em>Note: Notice the Suite name in the attribute.</em>
\section StatefulTests 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__.
\subsection StepMethods 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.
\subsection Stages 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.
\subsection ReturnValues Return values - void -> Will get executed only once. - bool -> Will get executed every tick until true is returned.
\subsection Result Result - Result is set via API member method of TestBase `SetResult(TestResultBase)`. - Setting a result which evaluates to failure will terminate the stage.
\subsection FailureUnwind 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.
\subsection Timeout 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")]
TestResultBase MyFooBarTest() { return TestBoolResult(5 > 3); }[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() { ... }
}Classes
Enums
Values
Main | ||
Setup | ||
TearDown |
Functions
proto native static TestSuite ActiveSuite() | Returns currently active TestSuite or null when none is active. | |
proto native static void Begin() | Starts up the testing process and initializes the structures. | |
override bool CanDo(ItemBase ingredients[], PlayerBase player) | ||
override void Do(ItemBase ingredients[], PlayerBase player, array<ItemBase> results, float specialty_weight) | ||
proto native static void End() | Finalizes the testing process. | |
bool Failure() | Return true of the result means failure. | more… |
string FailureText() | Text used for xml report output. | more… |
proto native static bool Finished() | Returns true when all tests and suites finished. | |
proto string GetName() [1/2] | Test name getter. Strictly for UI porposes! | |
proto string GetName() [2/2] | Suite class name getter. Strictly for UI porposes! | |
proto native static int GetNSuites() | Returns number of test suites. | |
proto native int GetNTests() | Returns the number for tests within this suite. | |
proto native TestResultBase GetResult() | Result getter. | |
proto native static TestSuite GetSuite(int handle) | Returns a test suite. | |
proto native TestBase GetTest(int handle) | Returns a test. | |
override void Init() | more… | |
proto native bool IsEnabled() [1/2] | Enabled flag getter. | |
proto native bool IsEnabled() [2/2] | Enabled flag getter. | |
proto native bool NativeFailure() | ||
proto native string NativeFailureText() | ||
protected void OnInit() | Callback for user defined initialization. Called for all suites during TestHarness.Begin(). | |
proto static string Report() | Generates a xml report. | |
proto native static bool Run() | Starts the testing process. Returns true when all tests have finished. If some of them are still in progress false is reported. | |
proto native void SetEnabled(bool val) [1/2] | Enables/Disables the test. Disabled tests won't run at all. | |
proto native void SetEnabled(bool val) [2/2] | Enables/Disables the suites. Disabled suites won't run at all. | |
proto native void SetResult(TestResultBase res) [1/2] | Sets the test result. Failure can result in specialized behavior described in TestResultBase. | |
proto native void SetResult(TestResultBase res) [2/2] | Sets the suite result. Failure can result in specialized behavior described in TestResultBase. | |
void Step(EStage stage = EStage.Main) | ||
void Test(string suite, int timeoutS = 0, int timeoutMs = 0, int sortOrder = 0) | Defines a suite the test belongs to, its timeout value and order within the suite. |
Variables
int SortOrder | ||
EStage Stage | ||
string Suite | ||
int TimeoutMs | ||
int TimeoutS |
Function Documentation
FailureTestResultBase
bool Failure()Return true of the result means failure.
FailureTextTestResultBase
string FailureText()Text used for xml report output.
InitTest
override void Init()