This chapter describes a unit test scenario with all features available to the developer.
The app needs two users and a group to test all the functionality, so it is a good idea to create a scenario which is used in all tests.
Example |
scenario SCTwoUsers { User meyer; User mueller;
init = expression { CreateUserData @userdata; @userdata.crfirstname = "Julia <~testscope~>"; @userdata.crsurname = "Meyer"; @userdata.crlogname = "julia.meyer.<~sessionid~><~testscope~>@pair.com";
meyer = coouser.CreateTestUser(@userdata); mueller = coouser.CreateTestUser(null); } } |
Note:
To create users there is a special usecase FSCDUCXUNIT@1.1001:CreateTestUser. This usecase takes some initialization data and creates a valid user in the current environment.
To provide even more flexibility, a scenario can be based on another scenario, giving a hierarchy of scenarios.
Example |
scenario SCOneGroupTwoUsers: SCTwoUsers { Group pair;
init = expression { CreateGroupData @groupdata = { crmembers: [meyer, mueller], crshortname: "Pair <~testscope~>" };
pair = coouser.CreateTestGroup(@groupdata); } } |
Note:
To create groups there is a special usecase FSCDUCXUNIT@1.1001:CreateTestGroup. This usecase takes some initialization data and creates a valid group in the current environment.
All unit tests can use this scenario to create their test environment.
Example |
test UTFolder using SCOneGroupTwoUsers { string foldername;
init = expression { foldername = "TheFolderName"; cootx.Commit(); }
test = expression { %%ASSERT(meyer in pair.grmembers); %%ASSERT(mueller in pair.grmembers); coouser.SwitchToUser(meyer);
%%ASSERT(coort.GetCurrentUser().GetAddress() == meyer.GetAddress()); Folder fld = #Folder.ObjectCreate(); fld.objname = foldername + ::sessionid; cooroot.ObjectLock(true, true); cooroot.objchildren += fld; cootx.Commit(); fld.AddToTestSession(); coouser.SwitchToUser(mueller); %%ASSERT(coort.GetCurrentUser().GetAddress() == mueller.GetAddress()); cooroot.ObjectLock(true, true); cooroot.objchildren += fld; cootx.Commit(); coouser.SwitchToUser(); } } |
Note:
After executing the test, the created objects need to be deleted, regardless of the success or failure of the test. This can be achieved by registering the new objects to the test session with the use case FSCDUCXUNIT@1.1001:AddToTestSession.
Even in app.test these scenarios can be used to create the environment. All the required data for executing the tests are provided as parameters.
Example |
<Sequence clienttype="External" jarfile="apptest-commander.jar" classname="Commander"> <Execution action='Select' location='Commands.StartScenario'/> <Execution action='Set' location='Commands.StartScenario.Scenario' value='FSCDUCXUNIT@1.1001:SCOneGroupTwoUsers'/> <Execution action='Set' location='Commands.StartScenario.Address' value='{~Run.address~}'/> <Execution action='Set' location='Commands.StartScenario.Username' value='Administrator'/> <Execution action='Set' location='Commands.StartScenario.SessionId' value='abc'/> <Execution action='Set' location='Commands.StartScenario.Password' value='{~Login.password~}'/> <Execution action='Set' location='Commands.StartScenario.DefaultUserPassword' value='{~Login.password~}'/> <Execution action='Set' location='Commands.StartScenario.SSLVerify' value='false'/> <Execution action='Execute' location='Commands.StartScenario'/> <Set parameter='id' location='Commands.StartScenario.CreatedSessionId'/> <Set parameter='sessionerror' location='Commands.StartScenario.ErrorMessage'/> <Validation ok='"{~sessionerror~}"!=""' /> <Execution action='Close' location='Commands.StartScenario'/> </Sequence> |
To remove the created objects the session can be closed, also.
Example |
<Sequence clienttype="External" jarfile="apptest-commander.jar" classname="Commander"> <Execution action='Select' location='Commands.StopScenario'/> <Execution action='Set' location='Commands.StopScenario.SessionId' value='{~id~}'/> <Execution action='Set' location='Commands.StopScenario.Address' value='{~Run.address~}'/> <Execution action='Set' location='Commands.StopScenario.Username' value='Administrator'/> <Execution action='Set' location='Commands.StopScenario.Password' value='{~Login.password~}'/> <Execution action='Set' location='Commands.StopScenario.SSLVerify' value='false'/> <Execution action='Execute' location='Commands.StopScenario'/> <Set parameter='sessionerror' location='Commands.StopScenario.ErrorMessage'/> <Validation ok='"{~sessionerror~}"==""' /> <Execution action='Close' location='Commands.StopScenario'/> </Sequence> |