Custom Virtual User (VU) Example

For our example, assume we are testing a Java thick client application. Although the example is in Java, exactly the same process can be applied to create both C++ and .NET virtual users (VUs).

For simplicity, the Java application contains a single class, called "JavaThickClient", which contains just two methods: the "login" method logs in to the server using the username and password provided, and the "doSomething" method performs an operation on the server.

To test this application, we want to create a workflow containing two scripts: a Login script that will logon to the server, and a DoSomething script that will execute operations on the server. The Login script will be an initial script (i.e. run once at the start of the test) and the DoSomething script will be an iterated script that will be called repeatedly with different parameters.

Once we have a custom VU type, we need to add code to our newly created classes. For each VU in the test, we will need to create an instance of JavaThickClient, call the login method from the initial Login script, and then call the doSomething method from the iterated DoSomething script. It should be obvious then, that a JavaThickClient instance will need to have a longer lifetime than a single script. Therefore, we will store it as a private member of our custom virtual user class (see Relationship between VirtualUser and VirtualUserScript objects):

# v2.0 java

publicclass MyJavaVU extends com.facilita.fc.runtime.VirtualUser

{

private JavaThickClient javaThickClient;

@Override

publicvoid pre() throws Exception

{

...

Next, we will provide methods in the MyJavaVU class that delegate to the methods in the JavaThickClient class:

publicclass MyJavaVU extends com.facilita.fc.runtime.VirtualUser

{

private JavaThickClient javaThickClient;

publicvoid login(String username, String password)

{

this.javaThickClient = new JavaThickClient(username, password);

this.javaThickClient.login();

}

publicvoid doSomething(String parameter)

{

this.javaThickClient.doSomething(parameter);

}

@Override

publicvoid pre() throws Exception

{

...

We want to be able to call the methods on the MyJavaVU class directly from our scripts. To this end, we will add helper methods to our MyJavaVUScript class that forward calls to the MyJavaVU class: