[SilkTest]Overview of application states

Overview of application states

 When testing an application, you're likely to have a number of testcases that have identical setup steps. Rather than record the same steps over and again you can record the steps as an application state and then associate the application state with the relevant testcases.

 An application state is the state you want to your application to be in after the base state is restored but before you run one or more testcases. By creating an application state, you are creating reusable code that saves space and time. Furthermore, if you need to modify the Setup stage, you can change it once, in the application state routine.

 A testcase can have, at most, one application state associated with it. However, that application state may itself be based on another previously defined application state. For example, assume that:
  *  The testcase Find is associated with the application state Setup
  *  The application state Setup is based on the application state OpenFile
  *  The application state OpenFile is based on the built-in application state, DefaultBaseState.
  *  Silktest would execute the programs in this order:
   1. DefaultBaseState application state
   2. OpenFile application state
   3. Setup application state
   4. Find testcase

 If a testcase is based on a single application state, that application state must itself be based on DefaultBaseState in order for the testcase to use the recovery system. Similarly, if a testcase is based on a chain of application states, the final link in the chain must be DefaultBaseState. In this way, Silktest's built-in recovery system is still able to restore the application to its base state when necessary.

 

appstate declaration
 
 Action
  Declares an application state.

 Syntax
  appstate appstate1() [basedon appstate2]
   statements

   Variable  Description
   --------  ---------------------------------------------------
   appstate1  An identifier that specifies the name of the application state being declared.
   appstate2  Optional. An identifier that specifies an application state upon which to base the definitin of appstate1 or none. Statements
       in appstate2 are executed before those in appstate1 when the application state function is called. If omitted, none is assumed.
   statements  The 4Test statements that define the application state.

 Notes
  An application state is typically used to put an application into the state it should be in at the start of a testcase.
  You can define the application state from scratch or base the definition on another application state, which in turn can be based on another application state, and so on. The base state is the lowest level of application state in this chain of inheritance. The applicaton state DefaultBaseState is predefined for your use by SilkTest.

  To associate an application state with a testcase, use the appstate keyword when you define the testcase. The second example below associates the application state MyAppState (which is based on MyBaseState) with the testcase MyTestCase.
   * By default, SilkTest call the SetAppState function when you enter a testcase, in the DefaultTestCaseEnter function.
   * The SetAppState functin executes the statements defined in the application state and in each of the application states upon which it is based, starting with the statements in the base state and working up to the application state chain.
   * By default, SilkTest calls the SetBaseState function when you exit a testcase, in the DefaulttestCaseExit function.
   * The SetBaseState function executes the statements defined in the lowest level application state only(the base state). For example, suppose a testcase uses the application state AppState3, base on AppState2, based on AppState1. Calling the SetBaseState function executes only the statements in the AppState1.

 Example
  appstate MyAppState() basedon MyBaseState
  //...
  testcase MyTestCase() appstate MyAppState
  //...


SetBaseState function
 
 Action
  Calls the base state function associated with the current machine.

 Syntax
  SetBaseState(sAppState)

  Variable  Description
  --------  ----------------------------------------------------
  sAppState  Optional. the name of the application state functin.

 Notes
  You can use SetBaseState without the optional argument when you are testing a single application from a testcase. However, the DefaultTestCaseExit function automatically calls SetBaseState when you eixt the testcase. so it is rarely necessary to call this functin. In a multi-client testing environment you must execute SetBaseState for each client. This invocation does not need to be within a testcase. Howerver, as with the single application case, you probably will not call this function. You may need call SetMultiBaseStates, which calls SetBaseState for each connected machine, but SetMultiBaseStates is also called automatically.

  As shown in the example, you define application satates with the appstate declaration. The definition for an application state can be based on another application state, which can be based on another and so on. The base state is lowest level of application state in this chain of inheritance.

  You associate an application state with a testcase when you declare the testcase, as shown in the testcase declaration in the example. In the client/Server environment, you must explicitly associate an application state with each machine being tested by the testcase; you do this with the SetMachine function.

  Calling SetBaseState for a testcase executes the statements associated with the base state --- that is, the application state at the bottom of the appstate chain.

  In the example below, the testcase uses the application state MyAppState, based on MyBaseState. Calling the SetBaseState function executes only the statements in MyBaseState.

 Example
  appstate MyAppState() basedon MyBaseState
   //Code to bring the application to the proper state...

  appstate MyBaseState()
   //Code to bring the application the base state...

  multitestcase MyTestCase(LIST OF STRING lsMachine)
   for each sMachine in lsMachine
    SetUpMachine(sMachine, Design, MyAppState)    /* SetUpMachine(sMachine[, wMainWin[, sAppState]])
                   Variable  Description
                   --------  -------------------------------------------------
                   sMachine  The name of the machine being set up. STRING.
                   wMainWin  Optional. The main window of the application being tested on this machine, as defined the main window declaration ofr this testcase. WINDOW
                   sAppState  Optional. The name of the application state to be associated with this machine for this testcase. STRING. */
    
   //Call SetMultiAppStates, which calls SetAppState(MyAppState)
   SetMultiAppStates()
   //Body of testcase goed here....

   //The exiting testcase calls DefaultMultiTestCaseExit, which calls SetBaseState(MyBaseState)
  
    
    

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值