It does not generate test classes automatically as I saw several other apps attend to do, but instead the app provide simple UI for generate test data and the test processes and finally generate 2 output files:
1.Static resource file that contains the test meta data.
2.Apex test class that run the test.
Using the app require permission: Customize Application.
In addition you should have at least Salesforce Developer basic knowledge.
Following are the main steps for creating new apex test class with the app:
1.Go to tab Test Class Builder
2.Either provide name for new test or select test file that was created before.
3.In the Test Data section you can create data that will be created before the test (before Test.StartTest()). Can either create new data using the icon or import data from the current environment using the icon.
- Can add connections between the records by clicking the icon next to the record and set the relevant lookup field.
- Known limitation: rich text fields being displayed as regular text area field.
4.In the Test Parameters section you can define parameters that will be used during the test.
For example, if you added few accounts in the test data and you need to test function that receive list of accounts you can create list parameter with those accounts.
If you need to use specific field from the test record as parameter you can also create parameter for that purpose
5.Create Test Process by clicking the icon at top.
In each test process you can have 3 steps:
5.1 Data manipulation. Add by the icon.
Usually used to test triggers functionality. For example if you have logic that invoked from trigger when opportunity is closed, you should update the opportunity to close.
5.2 Methods invocation. Add by theicon.
Used to call directly to apex function inside classes.
First type the class you want to test and select it, the page will show all the functions in this class. Select the relevant functions and click button Add Selected.
- For this demo I created simple apex class with 2 functions: first receive list of account records and print their names, second receive account Id parameter and close its opportunities
- If the function receive parameters you can set them by selecting parameters that were defined under Test Parameters.
- Use the icon to reorder the function order. The order in the page is the order that the functions will be executed.
5.3 Assert. Add by the icon.
Can be used to verify your test complete as expected.
Select the Assert Type (for now only 1 option exists Field Value) and click the icon to choose the record, field, expected value and error message to show if the assert failed.
6.Click the icon to generate your test files.
You can receive email with the 2 output files, or if it is sandbox you can directly deploy the files to this org.
If you deployed the files, you should find your apex test class under the name {input name at start}Test, in our demo it will be demo01Test.
- If using in sandbox and you want to use the deploy option you should first add remote site setting with your current org. If you not sure what is the URL, just try the deployment and you will receive appropriate message indicating which URL should be added.
- You can modify the apex classes that was generated by the app. For example if you have complex logic that is hard to implement with the app, you can use the app only to create the test data and then write the test logic by yourself in the output file.
Finally, run the test class and after verifying the coverage deploy to production both the static resource and the apex text class.
Installation link
Sample video:
😏
No comments:
Post a Comment