Unit Test Runner support for JustMock
The test runner fully supports JustMock so you can run both "elevated" and "non-elevated" unit tests with Telerik® JustCode™.
No matter whether the tests use JustMock or not, you run and debug all tests in the same way. Refer to the Run and Debug Tests topic.
A warning is shown when a mock object doesn't have any arranges set or is not used in any mock assert. By default, this warning is turned off.
You can turn it on from JustCode's options dialog.
This warning is available only for C# code.
Let's consider the following code:
public void CalculateTax_PositiveInput_Success()
var target = Mock.Create<Calculator>();
double total = 100F;
double tax = 0F;
double expected = 100F;
actual = target.CalculateTax(total, tax);
There are no arranges for target. Telerik® JustCode™ warns you for that in the Error List Window and in the Marker Bar.
Quick Fix: Add New Arranges for Mock Object
To fix the mock warning, we provide a special quick fix - Add New Arranges For This Mock Object.
You can quickly add arranges for the currently unused mock object without writing a single line of code.
- Position the caret over an unused mock object.
Press Alt+Enter. From the pop-up menu, select Add New Arranges For This Mock Object.
Select the member you'd like to set an arrangement for and click Add.
In the dialog you can set expectations for the selected member. You can configure the return type of the method, as well as all the parameters that it accepts. You can use JustMock Matchers (Any), a default value or a specific value to pass as a parameter.
By clicking Finish you get as a result an arrange statement for the selected member without writing a single line of code.
Create Mock Arrange
Even if you already have some arranges set for a mock object, you can still take advantage of the dialog for setting a new arrange statement.
Position the caret over the Mock.Create method.
Press Alt+Insert. From the pop-up menu, select Create Mock Arrange...
This will lead you through the same steps as in the Add New Arranges For This Mock Object fix.
In order to rename, you can also navigate on the main menu. Choose JustCode | Refactor | Create Mock Arrange..., or just press Ctrl+R, Ctrl+K.