Performance Toolkit in Business Central – Part 2
In this second part we are going to look into how you can create the test codeunits. Part 1 you can lookup here: Performance Toolkit in Business Central – Part 1 | LinkedIn
If you have interviewed the customer and you have got all there processes you need to make small steps of that. For example a customer going to create a purchase order you can make the following steps: create vendor (if you don’t use excisting data), open purchase order list, create new purchase order, post purchase order.
But how do you do that in code?
First you have to create a codeunit. If you use the property subtype = test then the codeunit must be run in the foreground. If you have a normal codeunit it can be run in the background in the BCPT tool (performance toolkit).
Be aware that the BCPT doesn’t run in isolation modus! So all the data will be committed into the database.
If you want to measure a seperate process you can call function StartScenario and if the call the EndScenario function (with exact the same description) the duration and sql statements will be measured between those functions.
You can also use the function UserWait. With this function you can interact a user. The ms you can fill in the field “Min. User Delay (ms)” and “Max. User Delay (ms)” on the line. Also in this function there is a commit.
Tip: Because you simulate a large number of users just sprinkle with commits in your code 😊
Be aware that if you use the StartScenario and EndScenario it will take the UserWaits into the calculation of the duration! For example you have the following test codeunit:
You get the following results:
“Add Order” is without UserWaits so it takes only 20 seconds. But “Enter Acc.” you can see there is a userwait. So that will be 10 (60-50) + 40 (100-60) = 50. Every test codeunit will also write a Scenario line in the log entries. This is without the UserWaits. But it is with that start-up time. So in this case: 10 + 20 (“Add Order”) + 10 (“Enter Acc.”) = 40.
Creating parameters
You can also work with parameters in your codeunit. These parameters you can enter on your line. For example you want with or without the UserWaits. Or you use excisting data or you want to create data.
First you have to create a codeunit that implements “BCPT Test Parm. Provider”
Here you can put all your parameters. After you have done this you have to create an enum extension that extends “BCPT Test Param. Enum”. So in this case you can use the same parameters for multiple codeunits.
Once you have done this you can start using the parameters in your codeunits:
So now you can write your own test codeunits.
Tip: to create very fast codeunits you can pick the library codeunits from the test framework!
Tip: If you have a message handler of a confirmhandler in your AL Code you can handle that also use the HandlerFunctions:
Tip: You can use the OpenView from the test framework so simulate real users. But do not use the GotoRecord function. Because that is just a rec.next until you got the record.
In my second and last blog I will take a look to how you can start the BCPT suite and analyse the results.
Leave a Reply