Quick Start
Write your first module test in minutes.
Your First Test
Create RandomNumberModuleTests.cs:
using Xunit;
using Crosser.EdgeNode.Modules.Testing;
using Crosser.EdgeNode.Flows.Models.Abstractions.Models;
namespace MyOrg.FlowModule.RandomNumberModule.Tests;
public class RandomNumberModuleTests
{
[Fact]
public async Task GeneratesRandomNumberInRange()
{
// Arrange
var module = new RandomNumberModule();
module.Settings.TargetMin = 10;
module.Settings.TargetMax = 20;
module.Settings.TargetName = "randomValue";
var flow = module.SetupFlow();
// Act
await flow.Start();
await flow.Receive(new FlowMessage());
var result = await flow.GetNextResult();
await flow.Stop();
// Assert
Assert.True(result.Has("randomValue"));
var value = result.Get<int>("randomValue");
Assert.InRange(value, 10, 19);
}
}
Run the Test
dotnet test
Expected output:
Passed! - Failed: 0, Passed: 1, Skipped: 0, Total: 1
Understanding the Test
- Arrange - Create and configure your module, setup test flow
- Act - Start flow, send message, retrieve result, stop flow
- Assert - Verify the module behaved correctly
Key Methods
SetupFlow()- Wraps module in test harnessStart()- Initializes and starts the moduleReceive(message)- Sends message to moduleGetNextResult()- Retrieves processed messageStop()- Stops the module
Next Steps
- Core Concepts - Understand TestFlow in depth
- Testing Guide - Complete API reference
- Advanced Testing - Complex scenarios