If you're building C# plugins or custom workflow activities in Dynamics 365 CE and not writing unit tests, you’re shipping blind.
We recently caught a bug in a plugin — one that would have slipped through manual UAT — only because we had a simple xUnit test in place. It saved us hours of rework and, more importantly, protected the production environment from a logic failure.
Here’s why test projects are a must-have in your Dynamics CE development workflow, and how to set them up effectively.
Why Testing Plugins Is Critical
1. Business Logic Lives in Code
Your plugins and custom workflows are often the core of your automation layer. Bugs here can:
- Corrupt data
- Block important updates
- Cause performance issues
2. Manual Testing Won’t Catch Everything
Relying on manual form testing in sandbox environments might miss:
- Edge cases
- Null value scenarios
- Integration failures
3. CI/CD Without Tests Is Risky
Automating solution deployment is great — but if there’s no safety net, you’re pushing untested logic directly through environments.
Tools You Can Use
- xUnit or NUnit – Widely adopted, easy to write, and supported by Azure DevOps.
- FakeXrmEasy – The go-to framework for mocking Dynamics CE context and services.
- Moq – Great for mocking interfaces like IOrganizationService in more complex scenarios.
- Dataverse DevTools for VS Code – Useful for organizing plugin + test code together with modern CLI support.
Project Structure Example
Here’s how we typically structure a solution:
/MyPluginSolution /Plugins - AccountCreatePlugin.cs /Tests - AccountCreatePluginTests.cs - Helpers.cs MyPluginSolution.sln
✅ Sample Test with FakeXrmEasy
public class AccountCreatePluginTests
{
[Fact]
public void Should_Set_Default_Value_When_Industry_Is_Blank()
{
var context = new XrmFakedContext();
var target = new Entity("account") { ["name"] = "Test Co" };
var pluginContext = context.GetDefaultPluginContext();
pluginContext.InputParameters["Target"] = target;
context.ExecutePluginWith<AccountCreatePlugin>(pluginContext);
Assert.Equal("Other", target["industrycode"]);
}
}
Best Practices
- Create test projects side-by-side with plugin projects.
- Follow naming conventions: AccountCreatePlugin.cs → AccountCreatePluginTests.cs.
- Use test data builders or helper methods to create reusable entities.
- Run tests as part of DevOps pipelines (Azure DevOps or GitHub Actions).
- Validate business outcomes, not just field assignments.
Final Thoughts
Writing unit tests for plugins isn't about perfection — it's about protection. You catch bugs early, document logic, and build trust in your automation layer.
Whether you’re just getting started with FakeXrmEasy or already working on advanced mocks with Moq, every test counts.
If you’re building serious solutions in Dynamics CE, test projects are non-negotiable.
Top comments (0)