Skip to content

Defining Test Parameters

itaiag edited this page Aug 14, 2016 · 2 revisions

Defining Test Parameters

The test parameters are “test class members”; In order to expose the test parameters to the JSystem runner, each parameter should have a setter and getter method

Code Example

package com.aqua.services.multiuser;

import junit.framework.SystemTestCase4;

import org.junit.Test;

/**
 * Test parameters simple example.
 */
public class TestParametersExample extends SystemTestCase4 {

	private String pingDestination;
	private int packetSize;

	@Test
	public void testPing() throws Exception {
		report.report("Test ping");
	}

	public String getPingDestination() {
		return pingDestination;
	}

	/**
	 * Destination of ping operation.
	 */
	public void setPingDestination(String pingDestination) {
		this.pingDestination = pingDestination;
	}

	public int getPacketSize() {
		return packetSize;
	}

	/**
	 * Size of packet which will be sent in ping message.
	 */
	public void setPacketSize(int packetSize) {
		this.packetSize = packetSize;
	}
}

JSystem JRunner GUI Representation

The “Defining Test Parameters” code example, as it appears in the JSystem JRunner.

The screen shot shows the default scenario setting in the left-hand scenarios panel of the JRunner, the “default” scenario contains one test, a “pingTest”. In order to access the test details “double click” on the test, the “Test Info” tab becomes active and appears in the forefront within the JRunner. The parameters panel appears within the “Test Info” tab and in it the two parameters that we have defined in our test are visible.

Test Parameters Types

JSystem supports the following test parameter types:

  • Primitive
  • Close Lists
  • java.util.File
  • java.util.Date
  • Java Beans

Primitives

JSystem Supported Primitives – float, double, long, int, Boolean, String.

Predefined List of Values

JSystem supports a “Predefined List of Values” for parameters in following two ways:

  • By defining parameter type to be an enum.
  • By defining parameter type to be String and adding the method public String[] getParamNameOptions(){..} were ParamName is the name of the parameter.

List Parameters Code Example

package com.aqua.services.multiuser;
import org.junit.Test;

import junit.framework.SystemTestCase4;
/**
* Test list parameters example.
*/
public class TestListParametersExample extends SystemTestCase4 {
	enum PacketSize {
		SMALL,
		MEDIUM,
		BIG;
	}
	private String pingDestination;
	private PacketSize packetSize;
	@Test
	public void testPingWithLists() throws Exception{
		report.report("Test ping");
	}
	public String getPingDestination() {
		return pingDestination;
	}
	public String[] getPingDestinationOptions(){
		return new String[]{"127.0.0.1","localhost"};
	}
	public void setPingDestination(String pingDestination) {
		this.pingDestination = pingDestination;
	}
	public PacketSize getPacketSize() {
		return packetSize;
	}
	public void setPacketSize(PacketSize packetSize) {
		this.packetSize = packetSize;
	}
}

The “PingDestination” parameters value is visualized as a drop down list. The list values that are returned by the method are “getPingDestinationOptions()”.

The “PackectSize” parameter value is also visualized as a drop down list, the list contains the values of the “PacketSize enum” type.

Supported Objects

In addition to primitives and lists, JSystem supports “java.io.File” types and “java.util.Date” objects.

Supported Objects Code Example

The code example shows a test with test parameters of type “java.io.File” and “java.util.Date” package com.aqua.services.multiuser;

import java.io.File;
import java.util.Date;

import org.junit.Test;

import junit.framework.SystemTestCase4;

/**
*/
public class TestAdvancedParametersExample extends SystemTestCase4 {
	private File folder;
	private Date createTime;

	@Test
	public void testVerifyFolderCreateTime() throws Exception {
		report.report("Test ping");
	}

	public File getFolder() {
		return folder;
	}

	public void setFolder(File folder) {
		this.folder = folder;
	}

	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}
}

JSystem JRunner GUI Representation

When editing File parameter values a button appears on the right of the value list called the “Parameter File Browser” button.

By pressing the value “Parameter File Browser” in the “Test Info” tab a file browser is opened.

When editing “CreateTime” parameter values the “Parameter File Browser” button appears on the right of the value list.

In order to open the “Date Editor”, press the “Parameter File Browser” button.

Grouping Parameters in Tabs

As the previous example shows, by default test parameters are shown in the “General” tab. When there are a large number of parameters, displaying all of the parameters in one tab becomes cumbersome.

The “@ParameterProperties” annotation allows the test author to group parameters in multiple tabs.

In order to group parameters together add the ”@ParameterProperties” annotation to the parameter setter, add the key “section” and define the section name as the value.

Grouping Parameters in Tabs Code Example

The code below shows a test in which test parameters are grouped into two tabs “Ping Configuration” and “Ping Destination”.

package com.aqua.services.multiuser;

import org.junit.Test;

import jsystem.framework.ParameterProperties;
import junit.framework.SystemTestCase4;

/**
 * Test parameters simple example.
 */
public class TestParametersWithSectionExample extends SystemTestCase4 {
	private String pingDestination;
	private int packetSize;

	@Test
	public void testPing() throws Exception {
		report.report("Test ping");
	}

	public String getPingDestination() {
		return pingDestination;
	}

	@ParameterProperties(description = "Destination of ping operation", section = "Ping Destination")
	public void setPingDestination(String pingDestination) {
		this.pingDestination = pingDestination;
	}

	public int getPacketSize() {
		return packetSize;
	}

	@ParameterProperties(description = "Size of packet which will be sent in ping message", section = "Ping Configuration")
	public void setPacketSize(int packetSize) {
		this.packetSize = packetSize;
	}
}

Note: You can also use the @ParameterProperties to define description to the parameter that will be shown in the JSystem runner

JSystem JRunner GUI Representation

As can be seen, the “General” tab was replaced with two new tabs:

  • The “Ping Configuration” tab that contains the PacketSize parameter.
  • The “Ping Destination” tab that contains the Ping Destination parameter.

Ordering Tabs

In order to control the order of the tabs in the parameters panel add the method:

Ordering Tabs Code Example

The code shows an example implementation of the method “sectionOrder” which signals the JRunner the order of parameters tabs.

public String[] sectionOrder() {
	return new String[]{"Tab1","Tab2”};
}
Clone this wiki locally