In this tutorial, you examine and test a database table that is part of the web application in Tutorial 5.
You use the SQL Database Execution (JDBC) step to interact with a database in a test case and test the response with an assertion. You examine the Users table from a Derby database that is part of the application.
Tutorial Tasks
In this tutorial, you:
Prerequisites
Follow these steps:
Store the properties that are necessary to connect to the database in the configuration. This practice is a standard DevTest practice that increases the portability of test cases.
Follow these steps:
org.apache.derby.jdbc.ClientDriver
jdbc:derby://localhost:1529/lisa-demo-server.db
sa
sa
The SQL Database Execution (JDBC) test step enables you to connect to a database using JDBC and make SQL queries on the database.
Follow these steps:
JDBC is added to the model editor.
To open the step editor, double-click the JDBC step.
To provide the connection information, use the properties that you added to the project.config configuration.
Follow these steps:
{{DBDriver}}
{{DBConnect}}
{{DBUserID}}
{{DBPwd}}
A message indicates that the connection is valid.
Now specify and run a SQL statement that retrieves data from the Users table.
Follow these steps:
SELECT LNAME, LOGIN FROM Users
A message confirms a valid query and displays the number of rows returned.
The Result Set tab is displayed.
Add an assertion that tests for the presence of a specific last name in the result set.
Follow these steps:
The Generate JDBC Result Set Value Assertion dialog opens.
If the last name that you selected is not found, then the test fails.
Follow these steps:
The test runs successfully. The result set is shown in the Response tab.
You now modify the assertion to cause the test to fail.
Follow these steps:
The assertion editor is opened. The lower portion indicates that the assertion checks the first column of the result set for the specified value.
The test fails.
Add a database filter that captures the value in the first column and fourth row of the result set. The value is stored in a property.
Follow these steps:
The filter editor opens.
This field is zero-based. Therefore, the value 3 refers to the fourth row.
Follow these steps:
The test fails because Johns was not found in the result set.
Notice that DBProperty was set to the value specified by the filter.
The Long Info Field area indicates that the assertion fired because the first column of the result set did not contain the value Johns.
In this tutorial, you created a test case to query a database. You used the Users table from the Apache Derby database that accompanies the applications on the demo server. You learned how to:
Copyright © 2014 CA Technologies.
All rights reserved.
|
|