如何通过编程方式禁用DUnit测试? [英] How can I disable DUnit tests by name programmatically?
问题描述
对于集成测试,我创建了一个DUnit测试套件,该套件对于第三方组件(消息代理)的每个版本都运行一次.不幸的是,由于某些版本的被测组件中存在已知的错误,某些测试总是会失败.
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.
这意味着测试套件永远不会完成100%.但是,对于自动化测试,需要100%的成功分数. DUnit没有提供一种现成的方法来按名称禁用测试套件中的测试.
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.
推荐答案
我编写了一个过程,该过程接受一个测试套件和一个测试名称列表,禁用具有匹配名称的所有测试,并执行到嵌套测试套件的递归操作
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;
用法示例(在Setup方法中创建了TStringlist'Excludes'):
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;
这篇关于如何通过编程方式禁用DUnit测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!