Using Serializable in Robotium RemoteControl

Released Jun 26, 2013 by Lei Wang and Carl Nagle

Contents

  1. What are RobotiumRC Serializable classes

  2. How to use Serializable classes in RobotiumRC

     2.1 Used directly
     2.2 Used internally
     2.3 When to implement a new custom class

         2.3.1 Standard Robotium waitForCondition Usage
         2.3.2 RobotiumRC waitForCondition Usage

  3. Why we need these Serializable classes

1. What are RobotiumRC Serializable classes?

RobotiumRC serializable classes are defined in the package:

    com.jayway.android.robotium.remotecontrol

They are compressed to a jar file:

    robotium-serializable.jar

After the installation of RobotiumRC, this jar file can be found in:

    <robotiumrc>\SoloRemoteControl\libs

For example C:\robotiumrc\SoloRemoteControl\libs if you accepted the default installation directory on Windows.

For now, this jar is including the following classes:

    com.jayway.android.robotium.remotecontrol.By
    com.jayway.android.robotium.remotecontrol.Condition
    com.jayway.android.robotium.remotecontrol.ObjectCollection
    com.jayway.android.robotium.remotecontrol.PointF

2. How to use Serializable classes in RobotiumRC

2.1 Used directly

2.2 Used internally

2.3 When to implement a new custom class

3. Why we need these Serializable classes

Before Robotium 4.0, Robotium's API solely used primitive types such as Strings and ints as API parameters. It was easy to pass these as String representations through the TCP Messenger from the controller side to the TestRunner on the device side.

Beginning with Robotium 4.0, Robotium introduced new APIs accepting complex object instances or Interfaces for some parameters. The most obvious example of this is the Condition Interface used in Solo.waitForCondition(Condition).

This Condition is just an Interface containing one method. Thus, RemoteControl has to have a way to pass the object implementing the Interface along with whatever objects the Interface might need to get its job done. We decided to pass the objects via Serialization between the controller and the TestRunner on the device. This requires the individual classes be Serializable--which the standard classes are not.

Robotium and Android classes NOT Serializable we have dealt with are listed below. There is a RemoteControl version of each of these classes that can be Serialized and sent to the TestRunner to satisfy the new Robotium API arguments:

    com.jayway.android.robotium.solo.By
    com.jayway.android.robotium.solo.Condition
    android.graphics.PointF

In addition, since it is often likely the Condition may need an object reference to the running TestRunner, or the traditional Robotium Solo object, or other native objects familiar to Robotium users gleaned from the TestRunner Instrumentation--we provide the device-side deserialized object with a reference to the TestRunner--which the controller side does not have and cannot provide.