Inserting Fail and Error actions

You can create complex portions of code in your test behavior to force Fail or Error test verdicts on certain conditions. For example, you might want to produce an Fail status if the program enters a certain portion of code that should not be executed.

To insert Fail or Error action:
  1. Open the test behavior source code in the Java editor. To find the source code, open the Package Explorer view, expand the test project you are storing the test in, and expand the Behavior folder.)
  2. Position the cursor at the location in the code where you want to insert the Fail or Error action. Although both Fail and Error work in the same way, a good practice is to use a Fail action for any condition where the component under test fails. Only use the Error action to detect an external problem or a bad test environment that causes the test to fail.
  3. Right-click and click Component Test > Insert Fail action or Insert Error action. This adds one of the following actions:
    ComponentTest.fail("");
    or
    ComponentTest.error("");
  4. If necessary, you can add a string as a parameter of the actions. This message will appear in the test report.
The following methods illustrate how to use the Error or Fail actions in a test behavior script.
public void testAddLocation() {

	LocationService locationService = new LocationService();
	Location location = new Location();
	location.setAddressLine1("841 Cameron Street");
	location.setCity("New York");
	location.setCountryCode("USA");

	try {
		locationService.add(location);
	} catch (Throwable t) {
		ComponentTest.fail("Add location failed");
	}
}

public void testConnectDB() {

	DB dataBase = new DB();
	try {
		dataBase.connect();
	} catch (ConnectionFailedException e) {
		ComponentTest.error("Unable to connect to database");
	}
}
Feedback
(C) Copyright IBM Corporation 2000, 2005. All Rights Reserved.