delphidunitx

When do we use Assert.Pass() in DUnitX?


It looks to me Assert.Pass("Some Message") does not do anything if I just put it in a test method:

procedure TRPMTestObject.TestPlatform;
begin
{$IFDEF WIN64}
  Assert.AreEqual(8, SizeOf(Pointer));
  Assert.Pass('WIN64 Defined');
{$ENDIF}
{$IFDEF WIN32}
  Assert.AreEqual(4, SizeOf(Pointer));
  Assert.Pass('WIN32 Defined');
{$ENDIF}
end;

It does not print to the test console... Any scenarios that we use this function?


Solution

  • Typically in a test you want to assert that something has the expected value. However sometimes you just want to make sure that something does not blow up (i.e. no exception was raised).

    Since frameworks such as DUnit or DUnitX have a detection for empty tests (tests that did not do any assert) you need to tell the framework that the test is not empty (you can do a dummy assert though). That is typically when you use Assert.Pass. It also allows you to leave the test early (if there is any case for that).

    So in your case where you call the Assert.AreEqual you don't need the Assert.Pass.