lculator.Test.cs and the class name to CalculatorTest. In the constructor of CalculatorTest, we need to create an object of the Calculator class. This can be done as shown in the listing below:
Unit Test for Add function
In the CalculatorTest class, add a unit test method to test the add functionality as shown in the listing below:
To run the test, navigate to the CalculatorApp.Services.Tests directory and execute the command:
You’ll get a ‘test failed’ output because the Add function is not implemented, as shown in the image below:
To pass the test, implement the Add function in the Calculator class as shown in the listing below:
To run the test now, navigate to the CalculatorApp.Services.Tests director and execute the command:
As output, you will get the ‘test passed’ message as shown in the image