I have used the unit test package that was initially included in the template download for Custom Actions. Unfortunately, I can no longer find the link for the project templates so I have included a sample of the project file with a some sample test code.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AssemblyName>Modules.SampleModule.Tests</AssemblyName>
<Version>1.0.0.0000</Version>
<AssemblyTitle>Modules.SampleModule.Tests</AssemblyTitle>
<TargetFramework>net472</TargetFramework>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="../Modules.SampleModule/Modules.SampleModule.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.PowerPlatform.PowerAutomate.Desktop.Actions.SDK" Version="1.4.*" />
<PackageReference Include="Microsoft.PowerPlatform.PowerAutomate.Desktop.Actions.SDK" Version="1.4.*-*" />
<PackageReference Include="Microsoft.PowerPlatform.PowerAutomate.Desktop.Actions.SDK.Tests" Version="1.4.*" />
<PackageReference Include="Microsoft.PowerPlatform.PowerAutomate.Desktop.Actions.SDK.Tests" Version="1.4.341-rc" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.*" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.*" />
</ItemGroup>
</Project>
using Microsoft.PowerPlatform.PowerAutomate.Desktop.Actions.SDK.Tests;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
namespace Modules.SampleModule.Tests
{
[TestClass]
public class Action1Tests
{
[TestMethod]
public void Action_IsValid()
{
bool isValid = ActionValidator.IsValid(typeof(Action1), out var errors);
Assert.IsTrue(isValid, $"Action is invalid. Validation Errors: {Environment.NewLine}{string.Join(Environment.NewLine, errors)}");
}
[TestMethod]
public void Action_Execute_Success()
{
try
{
Action1 action = new Action1() { InputArgument1 = "Test Input" };
action.Execute(null);
var actionOutput = action.OutputArgument1;
}
catch (Exception e)
{
Assert.Fail("Expected no exception, but got: " + e.Message);
}
}
}
}