[译]TILO-用于C和C ++的自动化单元测试工具
By robot-v1.0
本文链接 https://www.kyfws.com/applications/tilo-an-automated-unit-testing-tool-for-c-and-c-zh/
版权声明 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
- 9 分钟阅读 - 4410 个词 阅读量 0[译]TILO-用于C和C ++的自动化单元测试工具
原文地址:https://www.codeproject.com/Articles/11453/TILO-An-Automated-Unit-Testing-Tool-for-C-and-C
原文作者:Octavian Paul ROTARU, Gecko Pointdexter
译文由本站 robot-v1.0 翻译
前言
Tilo is a program / tool designed to help developers in creating and running unit tests. Unit tests will have to be coded, not written, and will be executed automatically by the tool.
Tilo是旨在帮助开发人员创建和运行单元测试的程序/工具.单元测试必须是编码的,而不是书面的,并且将由该工具自动执行.
介绍(Introduction)
Tilo是旨在帮助开发人员创建和运行单元测试的程序/工具.单元测试必须是编码的,而不是书面的,并且将由该工具自动执行.有关TILO的更多信息,请访问(Tilo is a program / tool designed to help developers create and run unit tests. Unit tests will have to be coded, not written, and will be executed automatically by the tool. For more information on TILO visit) TILO主页(TILO homepage) .(.)
它是如何工作的(How does it work)
程序员必须做什么(What the programmer has to do)
程序员要做的就是在每个DLL中创建一些函数,这些函数将执行单元测试并为成功返回true,为失败返回false.该工具只能用于测试DLL.程序员必须从每个DLL导出一些具有原型的函数:(All that the programmer has to do is create in each DLL, some functions which will perform the unit testing and return true for success and false for failure. The tool can only be used to test DLLs. The programmer must export from each DLL, some functions which have the prototype:)
bool FunctionName (char *pszNotes);
它将执行单元测试并返回(which will perform the unit testing and return) true
要么(or) false
,取决于结果.另外,程序员必须导出一个称为(, depending on the outcome. Also, the programmer must export a function called) GetUnitTestProcs
具有以下原型:(with the following prototype:)
void GetUnitTestProcs (char *pszUnitTestProcs);
该工具的作用(What the tool does)
该工具使用以下命令加载DLL(The tool loads the DLL using the) LoadLibrary
功能,通话(function, calls) GetUnitTestProcs
获取单元测试函数的名称,然后调用在(to get the names of the unit testing functions, and then calls each function returned in the) pszUnitTestProcs
参数.如果函数返回(parameter. If a function returns) false
,则表示单元测试失败,如果返回(, it means the unit test has failed, if it returns) true
这意味着它已经成功.(it means it has succeeded.)
设计(Design)
语言(Language)
该工具主要用C#编写,而模块则用C ++编写. C ++模块提供了本机Windows DLL与托管C#代码之间的接口.(The tool is written mostly in C#, and a module is written in C++. The C++ module provides an interface between the native Windows DLL and the managed C# code.)
模组(Modules)
该应用程序由四个模块组成.这些模块是:(The application is comprised of four modules. The modules are:)
- InvokeHelper,一个用C ++编写的DLL,其唯一目的是在本机DLL和C#托管代码之间提供接口.(InvokeHelper, a DLL written in C++ whose sole purpose is to provide an interface between the native DLLs and the C# managed code.)
- TestingBusiness,一个C#程序集,其中包含支持测试过程的业务的类.(TestingBusiness, a C# assembly which contains classes to support the business of the testing process.)
- 加载程序,一个C#程序集,用于处理从磁盘加载项目,保存项目等过程.(Loader, a C# assembly that deals with the process of loading the projects from disk, saving them etc.)
- GUI,一个C#Windows Forms可执行程序集.(GUI, a C# Windows Forms executable assembly.) 一个项目意味着要测试的一个或多个DLL.项目以XML格式保存到磁盘.(A project means one or more DLLs that are to be tested. Projects are saved to disk in XML format.)
每个模块的类(Classes per modules)
InvokeHelper类(InvokeHelper classes)
InvokeHelper DLL仅导出具有以下签名的两个函数:(The InvokeHelper DLL exports only two functions, with the following signatures:)
int CallGetUnitTestNames (char *strDllName, char *strTestNames);
int ExecuteUnitTest (char *strDllName, char *strTestName, char *strMsg);
的(The)CallGetUnitTestNames
函数只是加载称为的DLL(function simply loads the DLL called)strDllName
,找到(, finds the)GetUnitTestNames
该DLL中的函数并调用它,并传递(function in that DLL and calls it, passing the)strTestNames
参数.该函数应返回非零值表示成功,返回零值表示失败.(parameter to it. This function should return non-zero to indicate success and zero for failure.)
的(The) ExecuteUnitTest
函数以给定名称加载DLL,找到一个导出的函数,称为(function loads the DLL with the given name, finds an exported function called) strTestName
,使用调用该函数(, calls that function with) strMsg
作为参数并返回该函数返回的值,如果测试成功,则应为1(一),如果测试失败,则应为0(零).如果找不到该功能或发生其他错误,(as parameter and returns the value returned by that function, which should be 1 (one) if the test has succeeded and 0 (zero) if the test has failed. If the function cannot be found or other errors occur,) ExecuteUnitTest
应该返回适当的错误代码(错误代码从100开始).(should return an appropriate error code (error codes start at 100).)
TestBusiness类(TestBusiness classes)
该程序集包含四个类:(This assembly contains four classes:)
-
TestObject
-
UnitTest
(源自((derived from)TestObject
)()) -
Category
(源自((derived from)TestObject
)()) -
Module
(源自((derived from)TestObject
)()) -
Project
(源自((derived from)TestObject
)()) 一种(A)TestObject
class是模块中所有其他类的基类,并且提供了一些通用功能.它公开了以下成员:(class is the base class for all the other classes in the module and it provides some common functionalities. It exposes the following members:) -
Status
:一个只读属性,它是通过汇总所包含类别和单元测试的状态而获得的[可以是(: a read-only property that is obtained by aggregating the status of the contained categories and unit tests [which can be)NotRun
,(,)Running
,(,)Succeeded
,(,)Failed
,(,)Error
].(].) -
Execute
:将调用的方法(: a method which will call)Execute
在所有子类别上并包含(on all subcategories and contained)UnitTests
.(.) -
StatusChanged
:当单元测试的状态更改时将触发的事件.(: an event which will fire when the status of a unit test changes.) 一种(A)UnitTest
对象仅表示一个UnitTest.此类源自(object represents just that, a UnitTest. This class derives from)TestObject
.的(. The)UnitTest
类公开以下成员:(class exposes the following members:) -
Name
:一个只读的字符串属性,指定测试用例的名称.(: a read-only string property specifying the name of the test case.) -
FunctionName
:一个只读字符串属性,用于指定要调用的函数的名称.(: a read-only string property specifying the name of the function to be called.) -
Message
:一个只读的字符串属性,用于指定由(: a read-only string property specifying the message returned by the)Execute
方法.(method.) 一种(A)Category
对象代表测试用例的类别.它封装了一系列相关的测试用例.它可以包含其他类别,以便可以形成树结构,其中类别是节点,(object represents a category of test cases. It encapsulates a series of related test cases. It can contain other categories, so that a tree structure can be formed, where categories are nodes and)UnitTests
是叶子.此类源自(are leaves. This class derives from)TestObject
.的(. The)Category
类公开以下成员:(class exposes the following members:) -
Name
:指定类别名称的只读属性.(: a read-only property specifying the name of the category.) -
SubCategories
:一个(: an)ArrayList
零或更多(of zero or more)Category
对象,是此类别的子类别.(objects, which are subcategories of this category.) -
UnitTests
:一个(: an)ArrayList
的(of)UnitTest
可能包含零个或多个项目的对象.(objects which may contain zero or more items.) 一种(A)Module
对象表示一个需要测试的DLL.它包含一个或多个类别的单元测试.此类源自(object represents one DLL that needs to be tested. It contains one or more categories of unit tests. This class derives from)TestObject
.的(. The)Module
类公开以下成员:(class exposes the following members:) -
Name
:指定模块名称的读写字符串属性.(: a read-write string property specifying the name of the module.) -
DllName
:一个读写字符串属性,用于指定要加载的DLL的名称.(: a read-write string property specifying the name of the DLL to be loaded.) -
Categories
:一个(: an)ArrayList
一个或多个(of one or more)Category
对象.(objects.) 一种(A)Project
对象代表一个单元测试项目,该项目通常包含多个模块(要测试的DLL).此类源自(object represents one unit testing project, which typically contains several modules (DLLs to be tested). This class derives from)TestObject
.的(. The)Project
类公开以下成员:(class exposes the following members:) -
Name
:指定项目名称的读写字符串属性.(: a read-write string property specifying the name of the project.) -
Modules
:一个(: an)ArrayList
一个或多个项目模块.(of one or more project modules.)
装载机类(Loader classes)
该程序集包含处理读/写磁盘和加载项目的类.其中包含以下类:(This assembly contains classes that deal with reading/writing to disk and loading projects. The following classes are contained in it:)
-
Loader
-
Parser
-
UT
的(The)Loader
类将项目从磁盘加载并保存到磁盘.它使用(class loads and saves projects from and to disk. It uses the)Parser
在这个过程中上课.的(class in this process. The)Loader
类是一个单例,它公开以下成员:(class is a singleton which exposes the following members:) -
void LoadProjectFromDisk (Project prj, string strPath)
:从磁盘读取XML文件,并创建模块,类别和单元测试的结构.如果发生错误,将引发异常.(: reads an XML file from disk and creates a structure of modules, categories, unit tests. Throws an exception if errors occur.) -
void SaveProjectToDisk (Project prj, string strPath)
:写入包含项目结构的XML文件.(: writes an XML file containing the project structure.) -
static Loader Instance
:只读属性,提供对类的单例实例的访问.(: read-only property which provides access to the singleton instance of the class.) 的(The)Parser
类由(class is called by the)Loader
在加载阶段,解析由(during the loading stage, to parse the string returned by the)CallGetUnitTestNames
功能.的(function. The)Parser
公开以下成员:(exposes the following members:) -
Parser
构造函数:接受一个字符串参数.(constructor: takes in a string parameter.) -
UTs
:一个(: An)arrayList
UT结构的解析度,通过解析在构造过程中引入的字符串获得.(of UT structures, obtained by parsing the string taken in during construction.) 的(The)UT
类代表要加载的单元测试,因为它是从的输入字符串中读取的(class represents a unit test to be loaded, as it was read from the input string of the)Parser
.它公开了以下成员:(. It exposes the following members:) -
Name
:只读字符串属性,用于指定单元测试的名称.(: read-only string property specifying the name of the unit test.) -
Categories
:一个(: an)ArrayList
从上到下指定此单元测试类别的字符串.(of string specifying the categories of this unit test, from top to bottom.) -
FunctionName
:一个只读字符串属性,指定要执行的DLL导出函数的名称.(: a read-only string property specifying the name of the DLL exported function to be executed.)
为什么选择TILO?(Why TILO?)
**蒂洛(TILO)**是非洲神话中的上帝(马拉维和赞比亚的汤加部落).他是一个忙人.与大多数非洲众神不同,(is a God in the African mythology (Tongan tribes of Malawi and Zambia). He is a busybody. Unlike most of the African Gods,)**蒂洛(TILO)**喜欢参与其中.当事情不符合他的喜好时,他会大惊小怪,大怒.但是他总是在这里伸出援手. [资源:(likes to be involved. He fusses and gets into furious fits when things aren’t to his liking. But he is always there to lend a helping hand. [Source:) GodChecker.Com(GodChecker.Com) ](])
以类似的方式,我们的(In a similar way, our)**蒂洛(TILO)**总是参与其中.喜欢(always gets involved. Like)**蒂洛(TILO)**神,(the God,)**蒂洛(TILO)**单元测试工具意味着将单元测试用例嵌入到实际代码中.单元测试用例是代码:用于测试代码功能的驱动程序.(the Unit-Testing tool implies the embedding of the unit-test cases inside the actual code. Unit-test cases are code: driver programs used to test the functionality of your code.)**蒂洛(TILO)**是一个免费软件.您可以根据需要限制重新分配和/或修改它,但有以下限制:(is a free software. You can redistribute it and/or modify it as you like, with the following limitations:)
- 请勿更改其名称.(Do not change its name.)**蒂洛(TILO)**如果这样做,上帝会生气的.(the God will get angry if you do that.)
- 与我们分享您所做的任何增强(Share with us any enhancements that you have done to)蒂洛(TILO).(.) 分发该程序是希望它会有用,但没有任何保证;甚至没有对适销性或特定用途适用性的暗示保证.(This program is distributed with the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose.)
我们很高兴得知您正在使用(We’ll be glad to hear that you are using)蒂洛(TILO), 所以,请(, so please)让我们了解一下(let us know about it).随意地(. Feel free to)联系我们(contact us)如果您有关于TILO的任何查询.如果有任何缺陷(in case you have any query about TILO. If there is any defect)请告诉我们(please let us know).(.)
TILO的忠实主题,追随者和开发者:(TILO’s faithfull subjects, followers and developers:)
- 屋大维
保罗
罗塔鲁(Octavian-Paul ROTARU) - 离子Irinel Diaconu(Gec)(Ion Irinel Diaconu (Gec)) TILO主页(TILO Hompage)
许可
本文以及所有相关的源代码和文件均已获得The Code Project Open License (CPOL)的许可。
C++ C# VC7.1 .NET Windows Visual-Studio VS.NET2003 Dev 新闻 翻译