Unit Testing Activities¶
Overview¶
This guide explains how to effectively unit test activities using local knowledge for development.
Setting Up Local Knowledge¶
During development, it's often more efficient to use local knowledge rather than fetching it from Xians portal. This approach speeds up development and testing cycles. Here's how to set it up:
- Create a local knowledge folder (e.g.,
knowledge) - Store your knowledge files in this folder
- Set the environment variable in your tests:
File Matching¶
The file matching is done by the name of the file excluding the file extension.
Example:
ExampleProject.Knowledge/SalesMeeting.mdwill match instructions namedSalesMeetingExampleProject.Knowledge/Sales Meeting.mdwill match instructions namedSales MeetingExampleProject.Knowledge/My Sales Meeting.txtwill match instructions namedMy Sales Meeting
Test Structure Example¶
Here's a typical structure for activity unit tests where we use local knowledge folder:
Knowledge folder in the root of the test project: ExampleProject.Knowledge
public class ExampleActivityTests
{
private readonly ExampleActivity _activity;
private readonly string _projectRoot;
public ExampleActivityTests()
{
// Setup project root path
_projectRoot = Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..", "..", ".."));
// Load environment variables
DotNetEnv.Env.Load(Path.Combine(_projectRoot, "..", ".env"));
// *** Configure local knowledge ***
var knowledgeFolder = Path.Combine(_projectRoot, "..", "ExampleProject.Knowledge");
Environment.SetEnvironmentVariable("LOCAL_INSTRUCTIONS_FOLDER", knowledgeFolder);
// Initialize activity
_activity = new ExampleActivity();
}
[Fact]
public async Task ActivityMethod_Scenario_ExpectedBehavior()
{
// Arrange
var input = new InputModel
{
Property1 = "value1",
Property2 = "value2"
};
// Act
var result = await _activity.MethodUnderTest(input);
// Assert
Assert.True(result.Success);
Assert.Equal(expectedValue, result.Output);
}
}
Running Tests¶
- Use test filters to run specific tests:
- OR run all tests in the test class: