Static BDD Test: Creation of a GameObject

[File: Creation Of A GameObject Static Scenarios.unity]

The use of the inspector to choose the step methods for composing your scenario is not the only way to code your test scenario. You can also do it using the Static Components.

You can open the example scene “Creation Of A GameObject Static Scenarios.unity”. In this scene, you can see the same four tests we have already discussed. If you have a look of the inspector of the first one you can see the very same scenario for the first one of the previous scene, but in this case, you cannot choose the method steps using the inspector. All the information are coded in the BDD Component called “CreationOfGameObjectBDDStaticFirstScenario”.

There is just few information to add about this BDD Component compared to the previous one.


  • Class declaration

public class CreationOfGameObjectBDDStaticFirstScenario : StaticBDDComponent



The first difference is the class that our component inherits: StaticBDDComponent. In this case, we are telling the framework that all the information about the building of the scenario is coded into the class. It means that the inspector does not show the combo boxes and the “add/remove” buttons: you cannot modify the scenario using the inspector.


  • Methods declaration

[Given(1, "the software is just started and it is waiting for an input")]
   public IAssertionResult StartedAndWaitingForInput()

The declaration of the methods is not so different from the previous one: we have just to add a numeric parameter. This parameter tells to the framework the order of the methods it has to run during the execution of the test scenario. This parameter has to start from 1, and the numbering has to be sequential.


  • Methods Parameters

The methods defined in a Static Component cannot have parameters. This is because the static way for coding you test is meant to be used also if you are not sure to store the information in the inspector.


  • Number of BDD components

If in a Unity Integration Test there is a component with a StaticBDDComponent Class, all the non-Static components are ignored, and you cannot use them. Furthermore, you cannot have more than one Static Components in the same Unity Integration Test.


Q: Why do I have to choose the StaticBDDComponent classes instead of the Dynamic ones?

The use of the Dynamic Components let you reuse the same code, especially if all the test has the Given and When steps in common. With the Static Components, you have to duplicate your code for each class that describes a scenario.


All the information you put in the inspector for the Dynamic Component is stored in special arrays inside your component and inside the base class, stored using the inspector. If you do not pay attention, you could lose the setting previously stored in your integration test (please, read the section BDD Framework: how to use it and avoid mistakes for more information). If you use the Static Components, it is not going to happen.


Back to: Test 04 Read next: Methods Parameters Management


© 2017 Hud Dimension. All Rights Reserved.