Delphi DunitX FMX GUI 记录器
Delphi DunitX FMX GUI logger
我有一个基于控制台的 DUNITX 单元测试程序,我正在尝试将其转换为 FMX GUI 输出。阅读了 embarcadero 文档 here,我通过执行以下操作修改了测试程序文件:
- 包括 DUnitX.Loggers.GUIX 单位
- 注释掉DUnitX.Loggers.Console单元
- 注释掉 {$APPTYPE CONSOLE} 指令
- 将 Logger 更改为 logger := TGUIXTestRunner.Create(nil);
修改后的清单如下所示:
program HTMLParserTest;
{$IFNDEF TESTINSIGHT}
//{$APPTYPE CONSOLE}
{$ENDIF}{$STRONGLINKTYPES ON}
uses
System.SysUtils,
{$IFDEF TESTINSIGHT}
TestInsight.DUnitX,
{$ENDIF }
// DUnitX.Loggers.Console,
DUnitX.Loggers.GUIX,
DUnitX.Loggers.Xml.NUnit,
DUnitX.TestFramework,
test.ITUtils.Delphi in 'test.ITUtils.Delphi.pas',
ITUtils.Delphi in '..\Concept Test\ITUtils.Delphi.pas',
test.ITsimplehtmlparser.Delphi in 'test.ITsimplehtmlparser.Delphi.pas',
ITTools.simplehtmlparser.Delphi in '..\Concept
Test\ITTools.simplehtmlparser.Delphi.pas';
var
runner : ITestRunner;
results : IRunResults;
logger : ITestLogger;
nunitLogger : ITestLogger;
begin
{$IFDEF TESTINSIGHT}
TestInsight.DUnitX.RunRegisteredTests;
exit;
{$ENDIF}
try
//Check command line options, will exit if invalid
TDUnitX.CheckCommandLine;
//Create the test runner
runner := TDUnitX.CreateRunner;
//Tell the runner to use RTTI to find Fixtures
runner.UseRTTI := True;
//tell the runner how we will log things
//Log to the console window
// logger := TDUnitXConsoleLogger.Create(true);
logger := TGUIXTestRunner.Create(nil);
runner.AddLogger(logger);
//Generate an NUnit compatible XML File
nunitLogger := TDUnitXXMLNUnitFileLogger.Create(TDUnitX.Options.XMLOutputFile);
runner.AddLogger(nunitLogger);
runner.FailsOnNoAsserts := False; //When true, Assertions must be made during tests;
//Run tests
results := runner.Execute;
if not results.AllPassed then
System.ExitCode := EXIT_ERRORS;
{$IFNDEF CI}
//We don't want this happening when running under CI.
if TDUnitX.Options.ExitBehavior = TDUnitXExitBehavior.Pause then
begin
System.Write('Done.. press <Enter> key to quit.');
System.Readln;
end;
{$ENDIF}
except
on E: Exception do
System.Writeln(E.ClassName, ': ', E.Message);
end;
end.
当我 运行 这个(使用 Tokyo 10.2)时,我收到以下错误:
我还应该注意,我必须在我的库路径中包含 DUNITX 源的路径,因为它找不到要编译的 fmx 形式。
我想我在这里遗漏了一些东西,任何帮助将不胜感激,因为这方面的文档有点薄。
谢谢
这是我使用的模板,允许我在 VCL、FMX 或控制台应用程序之间进行选择:
program UnitTests;
///// UI Selection - Pick only 1! //////////////////////////////
{DEFINE UseVCL}
{$DEFINE UseFMX}
{DEFINE UseWinConsole}
////////////////////////////////////////////////////////////////
{$IFDEF UseWinConsole}
{$DEFINE UseConsole}
{$ENDIF}
{$IFDEF UseConsole}
{$APPTYPE CONSOLE}
{$ENDIF}
uses
{$IFDEF UseVCL}
VCL.Forms,
DUnitX.Loggers.GUI.VCL,
{$ENDIF}
{$IFDEF UseFMX}
FMX.Forms,
DUnitX.Loggers.GUIX,
{$ENDIF}
{$IFDEF UseConsole}
DUnitX.ConsoleWriter.Base,
DUnitX.Loggers.Console,
DUnitX.Loggers.XML.NUnit,
DUnitX.Loggers.Text,
DUnitX.Loggers.XML.xUnit,
{$ENDIF}
{$IFDEF UseWinConsole}
DUnitX.Windows.Console,
WinAPI.Windows,
WinAPI.Messages,
{$ENDIF}
System.SysUtils,
DUnitX.Generics,
DUnitX.InternalInterfaces,
DUnitX.WeakReference,
DUnitX.FixtureResult,
DUnitX.RunResults,
DUnitX.Test,
DUnitX.TestFixture,
DUnitX.TestFramework,
DUnitX.TestResult,
DUnitX.TestRunner,
DUnitX.Utils,
DUnitX.IoC,
DUnitX.MemoryLeakMonitor.Default,
// [TestFixturesUnit1] in '[TestFixturesUnit1].pas',
// [TestFixturesUnit2] in '[TestFixturesUnit2].pas',
// [TestFixturesUnit3] in '[TestFixturesUnit3].pas',
DUnitX.DUnitCompatibility;
{$R *.res}
/////////////////////////////////////////////////////////////////////////
{$IFDEF UseVCL}
begin
Application.Initialize;
Application.CreateForm(TGUIVCLTestRunner, GUIVCLTestRunner);
Application.Run;
{$ENDIF}
/////////////////////////////////////////////////////////////////////////
{$IFDEF UseFMX}
begin
Application.Initialize;
Application.CreateForm(TGUIXTestRunner, GUIXTestRunner);
Application.Run;
{$ENDIF}
/////////////////////////////////////////////////////////////////////////
{$IFDEF UseConsole}
var
runner : ITestRunner;
results : IRunResults;
logger : ITestLogger;
nunitLogger : ITestLogger;
begin
try
//Create the runner
runner := TDUnitX.CreateRunner;
runner.UseRTTI := True;
//tell the runner how we will log things
logger := TDUnitXConsoleLogger.Create(true);
nunitLogger := TDUnitXXMLNUnitFileLogger.Create;
runner.AddLogger(logger);
runner.AddLogger(nunitLogger);
//Run tests
results := runner.Execute;
System.Write('Done.. press <Enter> key to quit.');
System.Readln;
except
on E: Exception do
System.Writeln(E.ClassName, ': ', E.Message);
end;
{$ENDIF}
/////////////////////////////////////////////////////////////////////////
end.
我有一个基于控制台的 DUNITX 单元测试程序,我正在尝试将其转换为 FMX GUI 输出。阅读了 embarcadero 文档 here,我通过执行以下操作修改了测试程序文件:
- 包括 DUnitX.Loggers.GUIX 单位
- 注释掉DUnitX.Loggers.Console单元
- 注释掉 {$APPTYPE CONSOLE} 指令
- 将 Logger 更改为 logger := TGUIXTestRunner.Create(nil);
修改后的清单如下所示:
program HTMLParserTest;
{$IFNDEF TESTINSIGHT}
//{$APPTYPE CONSOLE}
{$ENDIF}{$STRONGLINKTYPES ON}
uses
System.SysUtils,
{$IFDEF TESTINSIGHT}
TestInsight.DUnitX,
{$ENDIF }
// DUnitX.Loggers.Console,
DUnitX.Loggers.GUIX,
DUnitX.Loggers.Xml.NUnit,
DUnitX.TestFramework,
test.ITUtils.Delphi in 'test.ITUtils.Delphi.pas',
ITUtils.Delphi in '..\Concept Test\ITUtils.Delphi.pas',
test.ITsimplehtmlparser.Delphi in 'test.ITsimplehtmlparser.Delphi.pas',
ITTools.simplehtmlparser.Delphi in '..\Concept
Test\ITTools.simplehtmlparser.Delphi.pas';
var
runner : ITestRunner;
results : IRunResults;
logger : ITestLogger;
nunitLogger : ITestLogger;
begin
{$IFDEF TESTINSIGHT}
TestInsight.DUnitX.RunRegisteredTests;
exit;
{$ENDIF}
try
//Check command line options, will exit if invalid
TDUnitX.CheckCommandLine;
//Create the test runner
runner := TDUnitX.CreateRunner;
//Tell the runner to use RTTI to find Fixtures
runner.UseRTTI := True;
//tell the runner how we will log things
//Log to the console window
// logger := TDUnitXConsoleLogger.Create(true);
logger := TGUIXTestRunner.Create(nil);
runner.AddLogger(logger);
//Generate an NUnit compatible XML File
nunitLogger := TDUnitXXMLNUnitFileLogger.Create(TDUnitX.Options.XMLOutputFile);
runner.AddLogger(nunitLogger);
runner.FailsOnNoAsserts := False; //When true, Assertions must be made during tests;
//Run tests
results := runner.Execute;
if not results.AllPassed then
System.ExitCode := EXIT_ERRORS;
{$IFNDEF CI}
//We don't want this happening when running under CI.
if TDUnitX.Options.ExitBehavior = TDUnitXExitBehavior.Pause then
begin
System.Write('Done.. press <Enter> key to quit.');
System.Readln;
end;
{$ENDIF}
except
on E: Exception do
System.Writeln(E.ClassName, ': ', E.Message);
end;
end.
当我 运行 这个(使用 Tokyo 10.2)时,我收到以下错误:
我还应该注意,我必须在我的库路径中包含 DUNITX 源的路径,因为它找不到要编译的 fmx 形式。
我想我在这里遗漏了一些东西,任何帮助将不胜感激,因为这方面的文档有点薄。
谢谢
这是我使用的模板,允许我在 VCL、FMX 或控制台应用程序之间进行选择:
program UnitTests;
///// UI Selection - Pick only 1! //////////////////////////////
{DEFINE UseVCL}
{$DEFINE UseFMX}
{DEFINE UseWinConsole}
////////////////////////////////////////////////////////////////
{$IFDEF UseWinConsole}
{$DEFINE UseConsole}
{$ENDIF}
{$IFDEF UseConsole}
{$APPTYPE CONSOLE}
{$ENDIF}
uses
{$IFDEF UseVCL}
VCL.Forms,
DUnitX.Loggers.GUI.VCL,
{$ENDIF}
{$IFDEF UseFMX}
FMX.Forms,
DUnitX.Loggers.GUIX,
{$ENDIF}
{$IFDEF UseConsole}
DUnitX.ConsoleWriter.Base,
DUnitX.Loggers.Console,
DUnitX.Loggers.XML.NUnit,
DUnitX.Loggers.Text,
DUnitX.Loggers.XML.xUnit,
{$ENDIF}
{$IFDEF UseWinConsole}
DUnitX.Windows.Console,
WinAPI.Windows,
WinAPI.Messages,
{$ENDIF}
System.SysUtils,
DUnitX.Generics,
DUnitX.InternalInterfaces,
DUnitX.WeakReference,
DUnitX.FixtureResult,
DUnitX.RunResults,
DUnitX.Test,
DUnitX.TestFixture,
DUnitX.TestFramework,
DUnitX.TestResult,
DUnitX.TestRunner,
DUnitX.Utils,
DUnitX.IoC,
DUnitX.MemoryLeakMonitor.Default,
// [TestFixturesUnit1] in '[TestFixturesUnit1].pas',
// [TestFixturesUnit2] in '[TestFixturesUnit2].pas',
// [TestFixturesUnit3] in '[TestFixturesUnit3].pas',
DUnitX.DUnitCompatibility;
{$R *.res}
/////////////////////////////////////////////////////////////////////////
{$IFDEF UseVCL}
begin
Application.Initialize;
Application.CreateForm(TGUIVCLTestRunner, GUIVCLTestRunner);
Application.Run;
{$ENDIF}
/////////////////////////////////////////////////////////////////////////
{$IFDEF UseFMX}
begin
Application.Initialize;
Application.CreateForm(TGUIXTestRunner, GUIXTestRunner);
Application.Run;
{$ENDIF}
/////////////////////////////////////////////////////////////////////////
{$IFDEF UseConsole}
var
runner : ITestRunner;
results : IRunResults;
logger : ITestLogger;
nunitLogger : ITestLogger;
begin
try
//Create the runner
runner := TDUnitX.CreateRunner;
runner.UseRTTI := True;
//tell the runner how we will log things
logger := TDUnitXConsoleLogger.Create(true);
nunitLogger := TDUnitXXMLNUnitFileLogger.Create;
runner.AddLogger(logger);
runner.AddLogger(nunitLogger);
//Run tests
results := runner.Execute;
System.Write('Done.. press <Enter> key to quit.');
System.Readln;
except
on E: Exception do
System.Writeln(E.ClassName, ': ', E.Message);
end;
{$ENDIF}
/////////////////////////////////////////////////////////////////////////
end.