soapUI basic knowledge

(0)
soapUI use guide:
show project information:  right-click the project,choose 'show project view';
create testSuite:  right-click the project,choose 'New TestSuite',and enter the testsuite name;
create testCase: 
right-click the created testsuite,choose 'New TestCase',and enter the testCase name;then show the case editor.
use testCase Editor to create necessary steps,such as: groovy script(delete data/init)/test request, and run the testCase.

the workspace file,such as**-workspace.xml,manage all projects address in this spaces. when System open this file, System will load projects base on this file.

you can open/close project just like eclipse.

show line number: right-click and choose the 'show line number';

can double-click the target testsuite,choose the 'run' to run all the testcase under this suite.
before runing testcase,the icon of soap request is white,after running, the color will be changed to green or red. green mean successful,red mean false.
(1)
add the assersion:
1.use the groovy script;
2.open the soap request,choose the 'Assersion' at the bottom tool bar.
  add 'SOAP Response': when the response come back,it will be true.
  add 'SOAP Fault':    when the response has error message,it will be true.
  add 'Contains':      when the response contain message which equal specific value, it will be true.

(2)
connect database:
the steps are enclosed as below:
1.copy the classes12.jar,jxl.jar under the directory: soapui_dir\bin\ext;

2.click the soap project,choose the 'custom properties' and add the db driver,url,username,password;
  such as:
  dbUser=aaa
  dbPassword=bbb
  dbUrl=jdbc:oracle:thin:@192.168.4.110:1521:ccapp
  dbDriverClassName=oracle.jdbc.driver.OracleDriver
3.go into target testcase,open the editor,switch to the tab 'setup script',input as following:
 
import groovy.sql.Sql    

def url = context.expand('${#Project#dbUrl}')
def driver = context.expand('${#Project#dbDriverClassName}')   
def user = context.expand('${#Project#dbUser}')   
def password = context.expand('${#Project#dbPassword}')       

if ( (null != url) && (null != driver) && (null != user) && (null != password) )  {      
try {        
connection = Sql.newInstance(url, user, password, driver)     
context.setProperty("dbConn", connection)    
log.info"connect Database is OK!!"
} catch (Exception e)  {         
log.error "Could not establish connection to the database."      
}   
}  

4.switch to tab 'teardown script'
  if(context.dbConn){context.dbConn.close()}

5.add groovy script for deleting/adding/querying data,such as:
delete:
if (context.dbConn){
    def sql = context.dbConn
    log.info"start delete  test_account data***********************************"
    sql.execute("delete from test_account where AC_ID>4")             
    sql.commit()    
    log.info" delete test_account data succussful!!"
}


init data:
if (context.dbConn){
    def sql = context.dbConn
    log.info"start insert  test_account data***********************************"
    sql.execute("insert into test_account values('5','account5')")             
    sql.execute("insert into test_account values('6','account6')")    
    sql.execute("insert into test_account values('7','account7')")    
    sql.execute("insert into test_account values('8','account8')")    
    sql.commit()    
    log.info" insert test_account data succussful!!"
}
note:
don't add the ';' into the sql, otherwise it will go wrong.


add assertion:
if(context.dbConn) {
    def sql = context.dbConn
    row = sql.firstRow("SELECT COUNT(*) AS TOTALRECORD FROM TEST_ACCOUNT")
    assert 6, row.TOTALRECORD
}
if all record number is 6,the unitcase will pass.

another:
if(context.dbConn) {
    def sql = context.dbConn
    row = sql.firstRow("SELECT T.a AS A FROM DDD T WHERE T.F = 1")
    assert ("SUBMITTED"==row.A)

    row1 = sql.firstRow("SELECT T.B AS B, T.c AS c FROM EE T WHERE T.F = 1")
    assert ("USD"==row1.B)
    assert (1234==row1.C)
}

NOTES:
if want to see the groovy script log,click the 'groovy log' at the bottom log bar.
 
other details are available from the attachment.
 

你可能感兴趣的:(职场,123,休闲)