Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
delphi窗体调用许多函数_Delphi_Unit Testing_Treeview - Fatal编程技术网

delphi窗体调用许多函数

delphi窗体调用许多函数,delphi,unit-testing,treeview,Delphi,Unit Testing,Treeview,我使用Embarcadero XE2在delphi中创建了一个库,我想测试它的函数和过程,但它们太多了(超过50个)。我想在我的库中创建一个表单来测试这些功能,在左侧有一个函数列表(带有类似treeview的选项),在表单右侧有可选的文本框和一个fireing按钮。我在网上找到了一些treeview教程,但是他们用treeview可视化了数据库 Treeview不是必需的,任何可能的函数枚举都是很好的 有什么简单的方法可以测试这么多函数吗?有没有更简单的方法来实现这个测试(表单) 我的库作为Op

我使用Embarcadero XE2在delphi中创建了一个库,我想测试它的函数和过程,但它们太多了(超过50个)。我想在我的库中创建一个表单来测试这些功能,在左侧有一个函数列表(带有类似treeview的选项),在表单右侧有可选的文本框和一个fireing按钮。我在网上找到了一些treeview教程,但是他们用treeview可视化了数据库

Treeview不是必需的,任何可能的函数枚举都是很好的

有什么简单的方法可以测试这么多函数吗?有没有更简单的方法来实现这个测试(表单)


我的库作为OpenOffice.orgAPI的折射器,它主要由过程组成,而不是函数,这些过程很难用单元测试框架进行测试,创建一个GUI来测试这个类会很好,因为我必须手动检查它们是如何工作的。这种测试有什么解决方案吗

改用Dunit。真的,你应该。这就是它的目的。


有一点学习曲线,但一旦你得到它,它将是“aahhh!”

你可以这样做,但这确实是错误的方法。你正在重新发明轮子,并设置自己错过测试的东西,因为你不能始终如一地、可靠地重复测试

测试应该是可重复的,并且应该始终使用尽可能多的可能的测试选项,这些选项可以在每次发生变化时进行测试,以确保不会引入错误(或将以前修复的错误放回),并允许您轻松支持新的选项、参数或值

您应该使用(Delphi单元测试),它包含在Delphi中,用于现在的几个版本(并可用于早期版本),它允许您自动化测试过程,并包括一个
TreeView
,其中显示测试设置(称为
Suites
)、组成该套件的各个测试以及每个测试的结果。它允许你测试应该有效的东西和不应该有效的东西(并确保它们不起作用),并且不断重复测试,这样你就不会错过任何东西。它还为您提供有关任何失败测试的信息,以及帮助您找到(并修复)失败条件的信息

在已经包含
DUnit
的Delphi版本中(我相信这是从delphi2007和更高版本开始的任何东西),使用
File->New->Other->unittests->testproject
创建shell。对于非基于类的测试,请创建另一个新单元并手动设置测试。这里有一个shell供您开始,其中包括对两个无意义函数的测试:

unit MyFunctionsTests;
{
  Delphi DUnit Test Case Skeleton Unit
}
interface

uses
  TestFramework, MyFunctions;

type
  // Test methods for MyFunctions unit
  // In the real world, you'd create separate test cases,
  // one for tests that should pass and one for tests that
  // should fail, and run them separately or in succession.
  // This is just a simple shell.
  TTestMyFunctions = class(TTestCase)
  strict private
  public
    procedure SetUp; override;
    procedure TearDown; override;
  published
    procedure TestFunctionOne;
    procedure TestFunctionTwo;
  end;

implementation

procedure TTestMyFunctions.Setup;
begin
  // Do any necessary initializations, set variables, etc.
end;

procedure TTestMyFunctions.TearDown;
begin
  // Free any objects, release any memory, etc. here
end;

procedure TTestMyFunctions.TestFunctionOne;
begin
  // FunctionOne takes two integers and adds them, and
  // returns the sum
  CheckTrue(FunctionOne(1, 1) = 2);  // Test success
  CheckFalse(FunctionOne(2, 2) = 5); // Test failure
end;

procedure TTestMyFunctions.TestFunctionTwo;
begin
  CheckEqualsString('AB', FunctionTwo('A', 'B')); // Success
  CheckFalse(FunctionTwo('B', 'A') = 'AB');       // Failure
end;

initialization
  // Register any test cases with the test runner
  RegisterTest(TTestMyFunctions.Suite);
end.
使用
Project->addtoproject
,并添加您的单元(
MyFunctions.pas
)和新的测试用例单元(
MyFunctionTests.pas
,在上面的shell中)。它应该是这样的:

program MyFunctionUnitTests;
{

  Delphi DUnit Test Project
  -------------------------
  This project contains the DUnit test framework and the GUI/Console test runners.
  Add "CONSOLE_TESTRUNNER" to the conditional defines entry in the project options
  to use the console test runner.  Otherwise the GUI test runner will be used by
  default.

}

{$IFDEF CONSOLE_TESTRUNNER}
{$APPTYPE CONSOLE}
{$ENDIF}

uses
  DUnitTestRunner,
  MyFunctions in '..\MyFunctions.pas',
  MyFunctionsTests in 'MyFunctionsTests.pas';

{$R *.RES}

begin
  DUnitTestRunner.RunRegisteredTests;
end.

现在运行项目,在出现的窗口中单击绿色的
Play
按钮(就像DelphiIDE中的run按钮)或点击F9。树视图将显示测试结果(绿色表示通过,红色表示失败)。如果测试失败,您可以在窗口底部查看该测试的错误信息。(如果您不能,请使用
查看
窗口显示错误。)

听起来您要执行一个任务?将它放在不同的选项卡中,例如复制?也许是时候去DUnit2了?感谢您提供的详细答案,我认为这真的很有帮助。虽然我有问题。我使用我的库作为OpenOffice.orgAPI的折射器,它主要由过程组成,而不是函数,使用这个“Dunit”shell很难测试,这就是为什么我认为创建一个GUI来测试这个类会很好,因为我必须手动检查它们是如何工作的。这种测试有什么解决办法吗?我不明白你的问题。如果你可以测试应用程序中的程序,你如何确定它是否有效?如果您可以判断成功或失败,那么很可能有一种方法可以自动化测试。“手动检查”通常意味着您保存成功的内容,然后使用它与自动测试进行比较,以判断您的测试是否通过。