Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test fails with current version of Mocks, passes with old version #127

Open
luebbe opened this issue Jun 10, 2020 · 2 comments
Open

Test fails with current version of Mocks, passes with old version #127

luebbe opened this issue Jun 10, 2020 · 2 comments

Comments

@luebbe
Copy link

luebbe commented Jun 10, 2020

Today I noticed that I am still using a really old version of Delphi Mocks (must be from ~2014 馃槆), so I decided to update. Alas, one of my tests fails with the current version.

The following test checks whether a log-channel receives one message of type A (siCategoriesChanged) and two messages of type B (siSubjectsChanged). So the same method is called multiple times with different parameters. The old version registered this correctly.

procedure TestLogging.TestNotification;
var
  MC: TMock<ILogChannel>;
begin
  MC := TMock<ILogChannel>.Create;

  try
    g_Logger.RegisterChannel(MC);

//    MC.Setup.Expect.Once.When.StatusChange([siCategoriesChanged]);
    MC.Setup.Expect.Exactly(1).When.StatusChange([siCategoriesChanged]);
    MC.Setup.Expect.Exactly(2).When.StatusChange([siSubjectsChanged]);

    // Check that the log channel receives one category and two subjects
    g_Logger.RegisterCategory('A Category');
    g_Logger.RegisterSubject('Ein Subject');
    g_Logger.RegisterSubject('Noch Ein Subject');

    g_Logger.UnregisterChannel(MC);

    Assert.WillNotRaise(
      procedure
      begin
        MC.Verify;
      end, EMockVerificationException);
  finally
    MC.Free;
  end;
end;

with the current version of Mocks, wiring up the mock channel like this:

    MC.Setup.Expect.Once.When.StatusChange([siCategoriesChanged]);
    MC.Setup.Expect.Exactly(2).When.StatusChange([siSubjectsChanged]);

results in:

Method raised an exception of type : EMockVerificationException
  Method : StatusChange
    Expectation [ Once When( [siCategoriesChanged] ) - Was 3 ] was not met.
    Expectation [ Exactly 2 Times When( [siSubjectsChanged] ) - Was 3 ] was not met.

and wiring up the channel like this:

    MC.Setup.Expect.Exactly(1).When.StatusChange([siCategoriesChanged]);
    MC.Setup.Expect.Exactly(2).When.StatusChange([siSubjectsChanged]);

results in:

EMockException with message '[ILogChannel] already defines Expectation Exactly for method [StatusChange] with args.'

plus a handful of EAccessViolation with message 'Zugriffsverletzung bei Adresse 0078A63B in Modul 'RAC.Logging.UnitTests.exe'. Lesen von Adresse 0000000C' in other tests.

No matter if I wire up the channel with Expect.Once or Expect.Exactly(1), the test passes in the old version of Mocks.

This looks like a regression bug to me.

@luebbe
Copy link
Author

luebbe commented Jun 10, 2020

Error Number 1:

Miscounting the function calls with parameters, when wiring up the test with Once and Exactly(2))
was introduced in:
d75a6db "Updated SameValue & CompareValue to improve testing.", 10.4.2020.

Error Number 2:

Exception '[ILogChannel] already defines Expectation Exactly for method [StatusChange] with args.' was introduced much earlier.

The oldest version that I can compile out of the box (with RAD Studio 10.3.3) is:
37a4ac3 "Added XE7 Support", 2.9.2014,
which already throws the '[ILogChannel] already defines Expectation Exactly for method [StatusChange] with args.' Exception when using Exactly(1) and Exactly(2). It passes when using Once and Exactly(2).

Edit: I went further back in time and even versions from 2011 throw the ILogChannel ... Exception.

@Laurensvanrun
Copy link
Contributor

@luebbe have you tried this with the latest version of Delphi Mocks? And does this issue still occurs?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants