In this article, we will discuss the ability to create integration tests with Dataverse. This functionality leverages the Power Fx capability to connect with Dataverse Entities. We will cover the following points:
$env:DATAVERSE_URL
.ForAll()
, Remove()
, CountRows()
, Collect()
, First()
.The onTestCaseStart
confuration in the sample provides an example of how to reset the current state before each test case. This ensures that each test starts with a clean slate. For example:
= ForAll(Accounts, Remove(Accounts, ThisRecord))
This line of code removes all records from the Accounts table.
The ForAll()
function is used to iterate over a table and perform an action on each record. In the example above, it is used to remove all records from the Accounts table. The Remove()
function is used to delete a specific record from a table.
When connecting to a Model Driven Application, you can specify the $env:DATAVERSE_URL
environment variable to connect. Additionally, you can use the Azure CLI to login to the Power Platform:
az login --use-device-code --allow-no-subscriptions
Here are some functions that are particularly useful when working with Dataverse:
As you create you test steps with Power Fx dataverse take into account the following:
Defaults() is not supported. As a result commands like Patch(Accounts, Defaults(Accounts), {name:"test"})
will not work.
As Use Collect()
to an alternative to Patch() with the Defaults() function
You can review thew Account entity sample which provides an example of integration tests that insert, update and delete account entities.