Recently the option to add tests to your Power Apps has been added. This this post I will have a look at this new experimental feature.
Tests (experimental)
Table of Contents
The new tests Feature can be found in the Advanced Tools option when you edit your Power Apps.
When you look at the tests the first thing you will find is a message that tells you to enable error management in your app.
Enable Error Management in your app
The Error Management feature is another new and experimental feature that you can enable. You can do this in the app settings.
Once you enabled the above feature you the Test Studio will be opened without the above mentioned dialogue.
Test Studio (Preview)
Test Studio is the place where you can create your tests.
I’m going to create a test by clicking o the record option. This is the easiest way to get started with building tests. There are other ways, but remember Power Apps is aimed at CITIZEN DEVELOPERS! I’m not a citizen developer therefore I will have a look at the pro developer options as well. But for now the record will do.
I select a few values in my drop downs and then click on the Done button. While I’m recording my test the recorder displays all the steps that I’m going through.
My test steps will now appear in the test definition and it looks like my test has been created.
It might be useful to rename the Step descriptions as the recorder will just repeat the steps action expressions.
Time to put this to the test!
Publish and Play the test
Once you are happy with your test you can Save, Publish and play your test. You will have to publish your test before you can play your test
When you play the app your recorded steps will be replayed. (Did you expect anything else?)
But on top of that you can also record your results. Note the OnTestCaseComplete step on the left hand side.
OnTestCaseComplete and OnTestSuiteComplete
The OnTestCaseComplete and OnTestSuiteComplete properties let you run things when the test case is complete.
You can use the TestCaseResult record and TestSuiteResult to collect the results of your test.
The expressions now are similar to the the expression that you would use in Power Apps. For example you could run a Patch to the Common Data Service.
A simple example is shown below:
//Save to Common Data Service Patch(AppTestResults , Defaults(AppTestResults) , { TestPass: TestCaseResult.TestCaseName & ":" & Text(Now()) ,TestSuiteId: TestCaseResult.TestSuiteId ,TestSuiteName: TestCaseResult.TestSuiteName ,TestCaseId: TestCaseResult.TestCaseId ,TestCaseName: TestCaseResult.TestCaseName ,StartTime: TestCaseResult.StartTime ,EndTime: TestCaseResult.EndTime ,TestSuccess: TestCaseResult.Success ,TestTraces: JSON(TestCaseResult.Traces) ,TestFailureMessage: TestCaseResult.TestFailureMessage } );
Manually editing your test
There are currently 4 test function that you can use. In the earlier screenshot you will have noticed the SetProperty function.
The 4 functions available in a test are:
The Select action matches a user selecting a control.
The SetProperty function is used to interact with a control just the same way as a user would do. So for example enter some text in a text field.
The Assert function lets you test for a specific value. This is used to check the expected value with the actual value that you get. If the expected and actual values don’t match then the test will fail.
The Trace function can be used to add extra information to the results form your OnTestCaseComplete.
If you try any other Power Apps function in your test cases then you will get a cannot be used in a test case warning.
For more learning about Power Apps testing
More details can be found on the following post: