How can I disable DUnit tests by name programmatically?

For integration tests, I created a DUnit test suite that runs once for each version of a third-party component (message broker). Unfortunately, some tests always fail due to known errors in some versions of the tested component.

This means that the test suite will never be completed with 100%. However, automated tests require a 100% success rate. DUnit does not offer a ready-made method for disabling tests in a test suite by name.

+3
source share
1 answer

I wrote a procedure that takes a set of tests and a list of test names, disables all tests with the corresponding name, and also recurses into nested test packages.

procedure DisableTests(const ATest: ITest; const AExclude: TStrings);
var
  I: Integer;
begin
  if AExclude.IndexOf(ATest.Name) <> -1  then
  begin
    ATest.Enabled := False;
  end;
  for I := 0 to ATest.Tests.Count - 1 do
  begin
    DisableTests(ATest.Tests[I] as ITest, AExclude);
  end
end;

Usage example (TStringlist "Exceptions" is created in the installation method):

procedure TSuiteVersion1beta2.SetUp;
begin
  // fill test suite
  inherited;

  // exclude some tests because they will fail anyway
  Excludes.Add('TestA');
  Excludes.Add('TestB');

  DisableTests(Self, Excludes);
end;
+6
source

Source: https://habr.com/ru/post/1776926/


All Articles