小编Mar*_*kus的帖子

spring4d 注销接口类型(spring4d、dunitx、delphi-mocks)

我正在使用 spring4d、dunitx 和 delphi-mocks 编写我的第一个单元测试。(spring4d 版本 1.1 - 2014 年 9 月 12 日)

在我的测试应用程序中,我将一个接口自动连接到我的被测系统类 (sut):

IMyInterface = interface [{yes, a GUID here}]
  function GetSomething1: TSomething1;
  function GetSomething2: TSomething2;
end;

TMyClass = class
private
    [Inject]
    FMyInterface: IMyInterface;
    // ...
end;
Run Code Online (Sandbox Code Playgroud)

现在,当我使用带有模拟的单元测试时,我使用以下(非常简单的)代码:

TMyTest = class
private
    [Test]
    procedure Test1;

    [Test]
    procedure Test2;
    // ...
end;

procedure TMyTest.Test1;
var
    aSut: TMyClass;
    aIntfMock: TMock<IMyInterface>;
    aSomething1: TSomething1;
begin
    // Arrange
    GlobalContainer.RegisterType<TMyClass>;

    aIntfMock := TMock<IMyInterface>.Create;
    try
        GlobalContainer.RegisterType<IMyInterface>.DelegateTo(
            function: IMyInterface
            begin
                Result := aIntfMock;
            end)
            .AsDefault; …
Run Code Online (Sandbox Code Playgroud)

delphi unit-testing spring4d delphi-mocks

5
推荐指数
1
解决办法
483
查看次数

标签 统计

delphi ×1

delphi-mocks ×1

spring4d ×1

unit-testing ×1