Unit Test - Hyland RPA - Foundation 23.2 - Foundation 23.2 - Ready - Hyland RPA - external

Hyland RPA

Platform
Hyland RPA
Product
Hyland RPA
Release
Foundation 23.2
License

Before we venture further into the application project, we need to consider test scenarios to validate future functions. We already defined the basic framework for our activities.

Now we create a new test class in the test project, using a public function. The attributes above the method header are test parameters.

As test parameters, we input calculations that contain all basic arithmetic operations. As a result, we expect the value 6 in all cases.

[TestCase("3 + 3", 6)]
[TestCase("7 - 1", 6)]
[TestCase("2 * 3", 6)]
[TestCase("36 / 6", 6)]
[TestCase("36 / 0", 0)]
public void CalculateFromString(string calculationString, int result)
{
}

Now it's on to the function body. Since our application project should contain the business logic, we have to create new classes and methods to enable the test scenario to execute these.

Let's create a new interface with a function CalculateFromString that returns the result of the calculation as int and accepts a string with the arithmetic formula as input.

public interface ICalculatorApplication
{
int CalculateFromString(string calculationString);
}

Afterward, we create a new class, that implements the interface, with the method CalculateFromString. Temporarily this method returns the value 0.

public class CalculatorApplication : ICalculatorApplication
{
public int CalculateFromString(string calculationString)
{
return 0;
}
}

After this is done we implement the function body of our test.

First, create a new variable of the type CalculatorApplication and initialize it. Directly after we call the CalculateFromString method and the parameters of our test, and assign the return value to a new variable of type int.

{
ICalculatorApplication calcApp = new CalculatorApplication();
int calculationResult = calcApp.CalculateFromString(calculationString);
}

The test class should now look as follows:

[TestFixture]
public class CalculateFromStringActivityTest
{
[Test]
[TestCase("3 + 3", 6)]
[TestCase("7 - 1", 6)]
[TestCase("2 * 3", 6)]
[TestCase("36 / 6", 6)]
[TestCase("36 / 0", 0)]

public void CalculateFromString(string calculationString, int result)
{
ICalculatorApplication calcApp = new CalculatorApplication();
int calculationResult =    calcApp.CalculateFromString(calculationString);
Assert.That(calculationResult, Is.EqualTo(result));
}
}

All tests will fail for now when you run the unit test, since the CalculateFromString method returns the value 0 at the moment, but the test expects a 6 as result.