- Overview
- Custom activities
- Migrating Activities to .NET 6
- Release Notes
- Building Workflow Analyzer Rules
- Building Activities Project Settings
- Creating Custom Wizards
- Prioritize Activities by Scope
- UiPath.Activities.Api.Base
- UiPath.Studio.Activities.Api
- UiPath.Studio.Activities.Api.Activities
- UiPath.Studio.Activities.Api.BusyService
- UiPath.Studio.Activities.Api.ExpressionEditor
- UiPath.Studio.Activities.Api.Expressions
- UiPath.Studio.Activities.Api.Licensing
- UiPath.Studio.Activities.Api.Mocking
- UiPath.Studio.Activities.Api.ObjectLibrary
- UiPath.Studio.Activities.Api.PackageBindings
- UiPath.Studio.Activities.Api.ProjectProperties
- UiPath.Studio.Activities.Api.ScopedActivities
- UiPath.Studio.Activities.Api.Settings
- UiPath.Studio.Activities.Api.Wizards
- UiPath.Studio.Activities.Api.Workflow
- UiPath.Studio.Api.Controls
- UiPath.Studio.Api.Telemetry
- UiPath.Studio.Api.Theme
- Robot JavaScript SDK
- Triggers SDK
Testing your activity
After implementing the new activity, it’s important to test that it works as expected. You can test your activity in one of the following ways.
The easiest and fastest way to test the activity code is to write unit tests that isolate the activity code and test individual scenarios.
For example:
[Theory]
[InlineData(1, Operation.Add, 1, 2)]
[InlineData(3, Operation.Subtract, 2, 1)]
[InlineData(3, Operation.Multiply, 2, 6)]
[InlineData(6, Operation.Divide, 2, 3)]
public void Calculator_ReturnsAsExpected(int firstNumber, Operation operation, int secondNumber, int expectedResult)
{
var calculator = new Calculator()
{
SelectedOperation = operation
};
var result = calculator.ExecuteInternal(firstNumber, secondNumber);
Assert.Equal(expectedResult, result);
}
[Theory]
[InlineData(1, Operation.Add, 1, 2)]
[InlineData(3, Operation.Subtract, 2, 1)]
[InlineData(3, Operation.Multiply, 2, 6)]
[InlineData(6, Operation.Divide, 2, 3)]
public void Calculator_ReturnsAsExpected(int firstNumber, Operation operation, int secondNumber, int expectedResult)
{
var calculator = new Calculator()
{
SelectedOperation = operation
};
var result = calculator.ExecuteInternal(firstNumber, secondNumber);
Assert.Equal(expectedResult, result);
}
Calculator
class and call the ExecuteInternal
function. There is nothing
specific related to activities in this context and basic unit testing principles
apply.
To see an example, go to the sample Calculator activity in GitHub.
WorkflowInvoker
class to place the activity inside a workflow
and run it as it would be run by UiPath Robot.
Let’s look at this example:
[Fact]
public void Divide_ReturnsAsExpected()
{
var activity = new Calculator()
{
FirstNumber = 4,
SecondNumber = 2,
SelectedOperation = Operation.Divide
};
var runner = new WorkflowInvoker(activity);
runner.Extensions.Add(() => workflowRuntimeMock.Object);
var result = runner.Invoke(TimeSpan.FromSeconds(1)); //the runner will return a dictionary with the values of the OutArguments
//verify that the result is as expected
Assert.Equal(2, result["Result"]);
//verify that we logged a message
workflowRuntimeMock.Verify(x => x.LogMessage(It.IsAny<LogMessage>()), Times.Once);
}
[Fact]
public void Divide_ReturnsAsExpected()
{
var activity = new Calculator()
{
FirstNumber = 4,
SecondNumber = 2,
SelectedOperation = Operation.Divide
};
var runner = new WorkflowInvoker(activity);
runner.Extensions.Add(() => workflowRuntimeMock.Object);
var result = runner.Invoke(TimeSpan.FromSeconds(1)); //the runner will return a dictionary with the values of the OutArguments
//verify that the result is as expected
Assert.Equal(2, result["Result"]);
//verify that we logged a message
workflowRuntimeMock.Verify(x => x.LogMessage(It.IsAny<LogMessage>()), Times.Once);
}
WorkflowInvoker
and run it as part of a workflow. The workflow
will eventually call the Execute
function on the
Calculator
class. Notice that this function is protected and we
could not invoke it directly, which is an indirect benefit of using this
approach.
WorkflowInvoker
execute it.
Sometimes, it is necessary to test the activity code inside the UiPath.Robot executor. To achieve this, we can use one of two options.
- Add
Debugger.Launch()
where you want the breakpoint to hit your code. - Build the new package and update the version in your project in UiPath.Studio, and then select Run.
-
The JIT Debugger prompts you to choose a Visual Studio instance to use for debugging.
-
After you select the instance, the JIT will stop the execution at the line where the
Debugger.Launch()
was added and from there the normal debug process can begin.
Another option is to delay the execution and then attach Visual Studio to the executor process. While this method requires more overhead, it allows debugging the activity code without modifications.
-
To delay execution, add the Delay activity or, in a Windows project, the Message Box activity.
-
Select Run, and then go to Visual Studio and select Debug > Attach to process.
-
Filter the process list by
UiPath.Executor
, select all processes, and then click Attach.
After the delay passes, the process execution is interrupted at the breakpoint you added in your code.