In all examples, the test registration methods are written in the class
type TCalc=class private class Procedure _RegisterMethod; // Register TestMethods class Function _TestMethods( IMethod:IRunMethodParam // Test Methods ):TTestResultParam;// Result Test ...
Registration methods can be prescribed anywhere, in any class and even without a class.
For example we can write registration methods in another class TCalcTest:
Class TCalcTest can be in the source module and external.
type TCalcTest=class private class Procedure _RegisterMethod; // Register TestMethods class Function _TestMethods( IMethod:IRunMethodParam // Test Methods ):TTestResultParam;// Result Test ...
ou can make a class collection for tests of various many classes
type TTestCollections=class private // TCalc class Procedure TCalc_RegisterMethod; // Register TestMethods class Function TCalc_TestMethods( IMethod:IRunMethodParam ):TTestResultParam; // TFiles class Procedure TFiles_RegisterMethod; // Register TestMethods class Function TFiles_TestMethods( IMethod:IRunMethodParam ):TTestResultParam; // TBitmap class Procedure TBitmap_RegisterMethod; // Register TestMethods class Function TBitmap_TestMethods( IMethod:IRunMethodParam ):TTestResultParam;
You can create test methods outside of classes by slightly changing their description
Procedure NoClass_RegisterMethod(Owner:TObject); // Register TestMethods Function NoClass_TestMethods(Owner:TObject;IMethod:IRunMethodParam):TTestResultParam;
and add the code at registration
var rm:TTestRegisterMethod; tm:TTestMethodsRun; begin ... TMethod(rm).Code:=@NoClass_RegisterMethod; TMethod(tm).Code:=@NoClass_TestMethods; L_pIndex_NoClass := IRegisterClass(rm,tm,'TCalc_NoClassTest','No Test classed');
You have a choice, you can do as you like.
But in my practice of testing (about 10 years), I can say that to store tests in the module and in the classroom, the most correct decision.
When you have a small project, everything is clear.
The individual modules working code, separate modules for tests, separate testing classes.
It seems simple and convenient.
But when a project becomes large with hundreds of working modules, hundreds of test modules appear at the same time.
And with the increase of the project increases the headache of supporting all these modules.
And with multi-user work, someone will forget to make changes to the test class, especially if you use a dirty hack to access data