Would be nice if TestInsight detected DSharp Mock<>.Verify as "checks"

Issue #54 closed
Rick Wheeler created an issue

In the following code example, TestInsight returns "No checks executed in TestCase", which I'm pretty just comes from DUnit. I know this can be fixed by adding the line "CheckTrue(True)" at the end of the test case, however since I'm using the DSharp library it would be cool if the "Mock<>.Verify" method was somehow picked up as a "Check" method and I don't have to litter my code with CheckTrue(True) statements.

Of course any other ideas would be welcomed as well.

procedure TestTUserService.SendWelcomeEmail;
var
  LUser: Mock<IUser>;
  LHttp: Mock<IHTTP>;
begin
  // Arrange
  LHttp.Setup.WillExecute.Once.WhenCallingWithAnyArguments.Post('');
  LUser.Setup.WillReturn<TNullableString>('AB55622E-4791-4F93-85B7-BAB1451827BE').Any.WhenCalling.Id;

  // Act
  FService.SendWelcomeEmail(LUser);

  // Assert
  LHttp.Verify;
end;

Comments (7)

  1. Stefan Glienke repo owner

    While it shows in TestInsight it's more of a DUnit issue. TestInsight does no magic. It just picks up the information that the used test framework provides. A mock has no connection to the test it is running in.

    DUnitX and it's assert class are solving this with a callback that is registered with the Assert class so the test knows that an assert was made during its execution. Something similar could be made here. But as I said, that is nothing that can or will be solved in the context of TestInsight.

    If you want to get rid of the warning though you can turn that off in TestInsight.DUnit.pas

  2. Rick Wheeler reporter

    Thanks for the fix Stefan, however it does not seem to be working for me. I downloaded the spring4d-compatibility branch and recompiled everything but it still tells me that no checks were executed. Is there something more I need to do? Thanks.

  3. Stefan Glienke repo owner

    Yes, adding the new unit to your project and using DSharp.Testing.DUnit in your testcase unit so it inherits from the TTestCase in that unit.

  4. Rick Wheeler reporter

    I'm feeling like a real dummy this morning since I cannot get this to work. I've attached a sample which I seems to be correct but I'm still getting the "No checks executed" warning from TestInsight.

  5. Stefan Glienke repo owner

    The step "adding the new unit to your project" is missing. That new file is called DSharp.Testing.Mock.DUnit and it establishing the connection between a mock and the testcase it is running in.

  6. Log in to comment