The BDD Framework in detail: the code reference

Print

DynamicBDDComponent

Every component has to inherit from the class DynamicBDDComponent to became a Dynamic Component. When it does, and it is attached to an Integration Test, in its inspector appears the logo of the Dynamic Component. It any logo appears, probably there is some build error, or the component does not inherit from DynamicBDDComponent class.

When a Dynamic Component is attached to an integration test, it is detected by the BDD Extension Runner that scans the content of the component looking for the Given-When-Then BDD Methods to show in the combo boxes in the inspector. There can be more than one Dynamic Components attached to an integration test.

 

StaticBDDComponent

Every component has to inherit from the class StaticBDDComponent to became a Static Component. When it does, and it is attached to an Integration Test, in its inspector appears the logo of the Static Component. It any logo appears, probably there is some build error, or the component does not inherit from StaticBDDComponent class.

When a Static Component is attached to an integration test, it is detected by the BDD Extension Runner that scans the content of the component looking for the Given-When-Then BDD Methods that compose the BDD Scenario to show in in the inspector. There can be only one Static Component attached to an integration test. If there is also a Dynamic Component, it is going to be ignored.


[HideInInspector]

This attribute is the standard Unity attribute that tells to Unity to not show the following public property on the inspector. It is used mostly for hiding the arrays with the property [ParametersValuesStorage]

 

[SerializeField]

This attribute is the standard Unity attribute that tells to Unity to use the following field as serialised property of the component. It has to be used if the field is not explicitly declared public.

 

[ParametersValuesStorage]

This attribute tells the framework to consider the following array as a storage for the methods parameters values inserted via the Unity inspector.

There has to be only one array for a type in the whole chain of inheritance.

There has to be one array for each type used in the parameters of the methods.

You cannot use this attribute for the Static Components.


protected Type[] arrayName;

It is the official declaration of a ParametersValuesStorage field. The type of the elements of the array has to be the same of the parameter you want to manage.

It has to be protected or private, and it has to be preceded by the [SerializeField] attribute for let the inspector to use it.

The possible types of the elements of the array have to follow these guidelines.

After inserting parameters values on the inspector, DO NOT rename or delete the array: you are going to lose all the values inserted via the inspector in all the integration tests and in all scenes you used it.

 

[Given|When|Then(string scenarioText, uint delay, uint timeout]

This attribute tells the framework to consider the following method as BDD Method for a Dynamic Scenario.

string scenarioText: mandatory: it is the text that describes the scenario, using a colloquial sentence that follows the words “Given”, "When", "Then" or "and".

Example: Given(“there is only one object in the scene”)

scenarioText: can contain the code %parameterName%, where parameterName is the name of a parameter in the method signature. The framework substitutes the code with the ToString() value of the parameter.

uint delay: optional: default value=0: it is the value in milliseconds of the delay request to run method.

uint timeout: optional: default value=3000:  it is the value in milliseconds of the timeout that can be reached for the Retry execution of the method. The timeout is interpreted by the BDD framework as an upper limit of time for the Retry operation for the execution of the Method. If the timeout is reached during the execution of the method, the method keeps running until it’s natural end.

There can be only one attribute of the same type for each method in the BDD Component.

There can be more than one BDD methods with the same attribute type in the BDD Component.

 

[Given|When|Then(uint executionOrder, string scenarioText, uint delay, uint timeout]

This attribute tells the framework to consider the following method as BDD Method for a Static Scenario.

uint executionOrder: mandatory:  it codes the order of the execution of all the Step Methods of the same step type (Given, When or Then). It has to start with the number 1 and the numbering has to be sequential.

string scenarioText: mandatory: it is the text that describes the scenario, using a colloquial sentence that follows the words “Given”, "When", "Then" or "and".

Example: Given(“there is only one object in the scene”)

uint delay: optional: default value=0: it is the value in milliseconds of the delay requested to run method.

uint timeout: optional: default value=3000:  it is the value in milliseconds of the timeout that can be reached for the Retry execution of the method. The timeout is interpreted by the BDD framework as an upper limit of time for the Retry operation for the execution of the Method. If the timeout is reached during the execution of the method, the method keeps running until it’s natural end.

There can be only one attribute of the same type for each method in the BDD Component.

There can be more than one BDD methods with the same attribute type in the BDD Component.

 

[CallBefore(uint executionOrder, string method, uint delay, uint timeout, string id)]

This attribute tells the BDD Framework to execute another BDD method action before executing the main BDD method.

There can be more than one [CallBefore] attributes for each BDD method.

A BDD method may not have a [CallBefore] attribute.

uint executionOrder: mandatory: it codes the order of the execution of all the methods of a group of a [CallBefore] attribute. It has to start with the number 1 and the numbering has to be sequential.

string Method: mandatory: it is the name of the BDD method that the BDD Framework has to execute. It has to be a valid BDD method defined inside the same BDD Component.

uint delay: optional: default value=0: it is the value in milliseconds of the delay requested to run method.

uint timeout: optional: default value=3000:  it is the value in milliseconds of the timeout that can be reached for the Retry execution of the method. The timeout is interpreted by the BDD framework as an upper limit of time for the Retry operation for the execution of the Method. If the timeout is reached during the execution of the method, the method keeps running until it’s natural end.

string id: optional: an arbitrary string to assure the unique identification of the parameter in the group of the [CallBefore] attribute.

 

public IAssertionResult MethodName(type1 parameterName1, type2 parameterName2, …)

This is the standard declaration of a BDD method for Dynamic Components.

It has to be public for letting the framework to access to it.

The return value has to be a standard implementation of the interface IAssertionResult.

The return value cannot be null.

The types of the parameters have to respect the rules described in this section.

After inserting values into the parameters via the inspector do not rename the parameters: you lose the values inserted previously.

A BDD method can have only one attribute [Given] at a time.

A BDD method can have only one attribute [When] at a time.

A BDD method can have only one attribute [Then] at a time.

A BDD method can have only one attribute [GenericBDDMethod] at a time.

A BDD method can have all the three [Given] [When] [Then] attributes at a time or a subset of them.

A BDD method has to have at least one of [Given] [When] [Then]  [GenericBDDMethod] attributes.

A BDD method can have one or more [CallBefore] attributes.

A BDD method may not have a [CallBefore] attribute.

 

AssertionResultSuccessful()

It is one of the three implementations of the interface IAssertionResult. A BDD method returns it if the result of the test performed is successful.

 

AssertionResultFailed(string text)

It is one of the three implementations of the interface IAssertionResult. A BDD method returns it if the test is failed or if there is some unexpected error during the execution of the method. The text string has to describe the error occurred and it is included in the integration test log. It rises a standard fail assertion for the Unity Test Tools.

 

AssertionResultRetry(string text)

It is one of the three implementations of the interface IAssertionResult. A BDD method returns it if the method has to wait for a pre-determined state of the software. If a timeout of 3 seconds, by default, or after a timeout defined with the timeout property is reached, the BDD Framework interprets the AssertionResultRetry as an AssertionResultFailed object. The text string has to describe the error occurred and it is included in the integration test log. If treated as an AssertionResultFailed object, it raises a standard fail assertion for the Unity Test Tools.

 

Back to: Runner Errors