2019 September Release

Defining a ScenarioPermanent link for this heading

Often different unit tests use the same basic setup. To ensure consistent tests, the init and cleanup code for these tests can be factored out into a so called scenario.

A scenario consists of some global variables, an expression to initialize the scenario and a cleanup expression.

A unit test can use a scenario to define the setting.

Example

scenario SCOneUser {
  User theuser;

  expression {

    theuser = #User.ObjectCreate();

  }

  cleanup = expression {

     theuser.ObjectDelete();

  }

}

test UTWithUser using SCOneUser {

  expression {

    string subject = theuser.objsubject;

  }

}

Scenarios can be based on another scenario, thus building a hierarchy of scenarios.

Example

scenario SCBase {
  Folder basefolder;

  expression {

    basefolder = #Folder.ObjectCreate();

  }

  cleanup = expression {

     basefolder.ObjectDelete();

  }

}

scenario SCDetail: SCBase {

  Folder detailfolder;

  expression {

    detailfolder = Folder.ObjectCreate();

    basefolder.ObjectLock(true, true);

    basefolder.objchildren += detailfolder;

  }

  cleanup = expression {

     detailfolder.ObjectDelete();

  }

}

test UTWithBothUsers using SCDetail {

  expression {

    string combinednames = basefolder.objname + detailfolder.objname;

  }

}