【发布时间】:2014-02-02 20:33:31
【问题描述】:
我有以下接口和类
interface
....
MyInterface = interface
['{079729DE-3E8C-4C1B-80AD-114F0A4CD04A}']
function MyFunction : integer;
procedure MyProcedure;
end;
TMyClass = class (TInterfacedObject, MyInterface)
private
FMyValue : integer;
public
function MyFunction : integer;
procedure MyProcedure;
end;
implementation
.....
function TMyClass.MyFunction: integer;
var
aResult : integer;
begin
{ here the value of AResult is changed}
result := aResult;
end;
procedure TMyClass.MyProcedure;
var
aValue : integer;
begin
{ here the value of FMyValue is changed}
{ here the value of aValue is changed}
end;
我可以通过 check (MyFunction=...) 轻松检查MyFunction 的结果,但我不知道如何在程序结束时检查FMyValye 和aValue 的值。
我宁愿避免在接口和类中添加一个额外的函数,该函数检索FMyValue 和aValue 的值,因为仅用于测试而不用于生产。
【问题讨论】:
-
不需要检查私有字段。如果公共方法执行它们应该执行的操作并且类本身的行为符合预期,则该值无关紧要。
标签: delphi unit-testing