Unity Integration Test 04

We are going to implement the requirement: “When I press the button “Delete” when there is not an object in the scene, I want to be warned by a message on the screen that there is not an object to destroy.

The scenario for this test is:

  • Given the software is just started and it is waiting for an input
  • When I press the button “Delete”
  • Then the warning message “Warning! No Object to delete!” has to appear on the scene.


The first two steps have not something new to explain; they are using the same features we already found.


Watching the Inspector for this test, we can see something different, compared to the other tests:



Looking at the image, we can notice that there is an indication that the row is expandible (marked with the red number):



Expanding the row, we can see another line: it is a parameter for the selected method. In this row, we can insert the value of the parameter. Let’s analyse the code in details:

   [Then("the warning message \"%expectedWarningText%\" has to appear in the scene", Delay = 1000f)]

   public IAssertionResult WarningInTheScene(string expectedWarningText)



Here we can see that the method, in this case, has a string parameter called “expectedWarningText”. This parameter is used inside the method body. The value of the parameter is passed by the framework using the value inserted on the inspector. The framework stores that value inside a particular structure inherited from the base class DynamicBDDComponent.

In this example, the type of the parameter is a System.string. The BDD framework can store values for all the types that Unity3D can manage as serialised property in the inspector, even if the property is custom. However, the BDD framework can natively manage just the Unity3D predetermined base types (see the chapter "Simple field types that can be serialized" on the Unity3D Documentation).

There is a way to add this feature for the others serialised types: for doing it, please read Methods Parameters Management.

Analysing in details the [Then] attribute you can see we are using the parameter name inside the step scenario description.

[Then("the warning message \"%expectedWarningText%\" appears in the scene", Delay = 1000f)]

With this syntax, you are telling the framework to substitute the code  %expectedWarningText% with the parameter value. You can see its effect in the previous image. Please, compare the step scenario description showed in the image with the sentence declared in the [Then] attribute to see the result.

Another aspect you could find interesting about this method is the use of the BDD class public property called WarningMessage. It is, of course, a pointer to a GameObject in the scene, passed by the inspector, as usual in the Unity development. It was just a reminder that the BDD Component is a Unity Component attached to the Integration Test, so you can develop your tests keeping in mind you can still use all your experience in Unity development.


Q: I have made a custom inspector for my serialised property. Does the framework recognise that?

Yes, of course. The framework uses the Unity property fields to draw the parameters on the inspector, so every update you make on your custom inspector is going to be reflected instantly on the BDD Runner view.


Q: What if I want to use a parameter that cannot be managed by the inspector?

In this case, the better way is to create that object programmatically inside you test code. You can put as parameter the data you need to build your object.


Back to: Unity Integration Test 03 Read next: BDD in action: Having a look at CubeManager class


© 2017 Hud Dimension. All Rights Reserved.