How can I disable DUnit tests by name programmatically?

一世执手 提交于 2019-12-07 16:26:37

问题


For integration tests, I created a DUnit test suite which runs once for every version of a third party component (a message broker). Unfortunately, some tests always fail because of known bugs in some versions of the tested component.

This means the test suites will never complete with 100%. For automated tests however, a 100% success score is required. DUnit does not offer a ready-made method to disable tests in a test suite by name.


回答1:


I wrote a procedure which takes a test suite and a list of test names, disables all tests with a matching name, and also performs a recursion into nested test suites.

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;

Example usage (the TStringlist ‘Excludes’ is created in the Setup 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;


来源:https://stackoverflow.com/questions/4279127/how-can-i-disable-dunit-tests-by-name-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!