delphi - 使用 TDUnitX.CurrentRunner.Log 时无日志输出
问题描述
我不确定如何使用 DUnitX 将一些字符串输出到控制台窗口,所以这是我的尝试:
unit Unit1;
interface
uses
DUnitX.TestFramework;
type
[TestFixture]
TMyTestObject = class(TObject)
public
// Sample Methods
// Simple single Test
// Test with TestCase Attribute to supply parameters.
[Test]
[TestCase('TestA','1,2,3')]
[TestCase('TestB','3,4,7')]
procedure Test1(AValue1, AValue2, _Result : Integer);
end;
procedure TMyTestObject.Test1(AValue1, AValue2, _Result: Integer);
begin
TDUnitX.CurrentRunner.Log(TLogLevel.Information, 'Information');
end;
initialization
TDUnitX.RegisterTestFixture(TMyTestObject);
end.
什么都没有打印出来,所以我应该怎么写呢?
解决方案
DUnitX 在单元 DUnitX.TestFramework 中使用一对 Log 和 Status 方法在 TObject 上定义了一个类助手。只要此单元在您的使用列表中,您就可以在任何对象上调用这些方法,例如通过以下方式:
uses
DUnitX.TestFramework;
[...]
procedure TMyTestObject.Test1(AValue1, AValue2, _Result: Integer);
begin
self.Log(TLogLevel.Information, 'Information');
end;
该语法之所以有效,是因为类助手是一种将方法和属性添加到已定义类的方法。通过在 TObject 上定义一个类助手,所有对象都被扩展了。
Embarcadero Wiki: Class and Record Helpers (Delphi)中描述了类助手
推荐阅读
- python - matplotlib的轴水平线重叠问题
- python - Python:修复符号链接库的导入
- c++ - C++ 的 Code::blocks 错误,提示“构建项目”
- firebase-cloud-messaging - 为使用 PWA builder 构建的 App 创建原生 Andriod 推送通知
- python - IOS 无效的重定向 URI
- python - 切换到 selenium 中的另一个弹出窗口 - python
- javascript - 在搜索/过滤列表 HTML/JS 中遇到问题
- android - 无法对 Motionlayout 中的两个不同元素执行两个操作 | 安卓工作室
- pycharm - 每当我打开 PyCharm 时,它都会显示启动错误
- android - MediaMetaDataRetriever 在 Android 10 上返回 null