Microsoft Power Apps includes a built-in testing framework called Test Studio, which allows you to create, run, and manage test suites for your applications. Follow this step-by-step guide to learn how to use it, including implementing a simple assertion.
Step 1: Open Your Power App in Edit Mode
Start by opening the Power App you want to test in edit mode. You can do this by going to the Power Apps portal and selecting “Apps” from the left-hand menu. Using the ellipse for the App you want to test, choose ‘Edit’.
Step 2: Open Test Studio
Once your app is in the editor, navigate to the left menu, select “Advanced Tools”, and then “Tests” (note, this is a new feature. In some environments, you may not yet be able to access it. If you cannot, try testing your app in a US location environment as features often arrive here first).
You will see a message about enabling Error management in your app. You should enable this within Upcoming features (at the time of writing).
Step 3: Create a New Test Case
You will be set up with a default Case and Test “Suite”. A Suite is a collection of related cases. To add more cases, click “+ New Step”. Name your test case something meaningful that describes what it will test.
Step 4: Start Recording
The quickest way to create test cases is to take actions in the App and record them. This will automatically record each click and action you take. You can then edit what you want the case to do quickly.
To do this, click the “Record” button to begin recording actions for your test case. The application will now track and record all the actions you take within the app.
Step 5: Perform Actions in Your App
Navigate through your app as a user would, performing actions you want to include in your test and recording them. This might involve clicking buttons, entering text, or navigating between screens.
Step 6: Insert an Assertion
Once you have a test case ‘script’ written you can repeat it as many times as you like. You can also insert an assertion at any point. An assertion is a condition that you expect to be true at a specific point in your test.
To do this, perform the following sub-steps:
- Within the cases that you have recorded, add a new step (use the above or below icons or just add one at the bottom)
- Define the assertion. Select the comparison type (like equals, contains, etc.) and enter the expected value.
- An example Assert statement looks like this “Assert(lblTitleLabel.text = “Hello”)”. This tells the Test studio to check the Text property of the lblTitleLabel at this point and see if it says “Hello”. If it does not, the Assert step will report a failure.
Step 7: Complete the Suite
Once you’ve completed all the actions (once you click Done on recordings it will generate a set of cases for you) and assertions for your test case you have a basic suite you can use to test your app.
Step 8: Save Your Test Case
After you’ve stopped recording, be sure to save and publish your test cases.
Step 9: Run Your Test Case
With your test case saved, you can now run it. Select your test case from the Test Studio list and click “Play.” You will see the results of your test case in the “Results” tab on the left.
Note: you may be asked to Publish the app at this point because test cases are linked to a published version.#
A final note to mention, if you click on the suite name, you are presented with 3 options to add a formula to the beginning of your test and the end. These can be useful for example in getting your Automation to a location in the App BEFORE the test cases run. E.g try adding Navigate(screenname) to the OnTestCaseStart property of your Test suite.
Step 10: Analyze the Results
After the test has finished running, review the results. If any of your assertions failed, you would need to debug and identify the cause of the failure.
Using the Test Studio in Power Apps, you can create comprehensive tests for your applications, helping you ensure their reliability and performance. And remember, the key to effective testing is regular and thorough execution of test cases, reviewing results, and iteratively improving your tests and your app based on your findings.
If you want to see this in action, check out our Collab365 Academy live stream