Base test methods

Every Native/Hybrid/Web mobile test inherits a base mobile test class that provides some additional functionality. For example, some code can be executed before the test is started or after the test is completed. In these cases you can override the OnBeforeTestStarted and OnAfterTestCompleted methods the base test class provides. The code bellow shows how to utilize this scenario and add sample test execution duration calculation to the test execution log.

protected override void OnAfterTestCompleted()
{
    Log.WriteLine("Test completed at: " + DateTime.Now.ToLongTimeString());
}

protected override void OnBeforeTestStarted()
{
    Log.WriteLine("Test started at: " + DateTime.Now.ToLongTimeString());
}
Protected Overrides Sub OnAfterTestCompleted()
    Log.WriteLine("Test completed at: " + DateTime.Now.ToLongTimeString())
End Sub

Protected Overrides Sub OnBeforeTestStarted()
    Log.WriteLine("Test started at: " + DateTime.Now.ToLongTimeString())
End Sub

Here is a completed view of the test code-behind file:

Test Base Methods Code

Executing the test provides a log file that contains the logged data:

Test Base Methods Log

See Also