Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2007-05

FPCUnit: TestSuiteName vs TestName

7 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Graeme Geldenhuys

Hi,

When would you use TestSuiteName and when TestName?

For example, the following I think is wrong.

constructor TTestSuite.Create(AName: string);
begin
  Create();
  FName := AName;
end;

Shouldn't this set the FTestSuiteName field?
Now if I do a TestSuite.TestSuiteName it doesn't return FName, instead it returns FTestSuiteName. If I do a TestSuit.TestName it returns the FName.

This problem seems to be confirmed with the following code:

constructor TTestSuite.Create(AClass: TClass; AName: string);
begin
  Create(AClass);
  FName := AName;
end;

This is getting very confusing. When are we supposed to use TestSuiteName and when do we use TestName?

For example in DUnit you can register a test as follows:
  RegisterTest(cSuiteNameNonPersistentTests, ATestCaseClass.Suite);

So if I want to implement this in FPCUnit, what name am I supposed to set?

Maybe I'm just getting confused with the difference between TTest, TTestCase and TTestSuite. I go read some more on this in the DUnit web page (do we have FPCUnit docs explaining this?).

Graeme Geldenhuys General error, hit any user to continue.

Reply by email

Dean Zobec
to Graeme Geldenhuys

Graeme,

Hi, When would you use TestSuiteName and when TestName?

TestSuiteName is the name of the TestSuite (parent) that contains the Test

Show quoted text 10 lines
For example, the following I think is wrong. constructor TTestSuite.Create(AName: string); begin Create(); FName := AName; end; Shouldn't this set the FTestSuiteName field?

No, FTestSuiteName is set only when the Suite is added to another TestSuite:

we have
procedure TTestSuite.AddTest(ATest: TTest);
begin
  FTests.Add(ATest);
  if ATest.TestSuiteName = '' then
    ATest.TestSuiteName := Self.TestName;
end;

The ATest parameter can be a TTestCase or a TTestSuite

Show quoted text 19 lines
Now if I do a TestSuite.TestSuiteName it doesn't return FName, instead it returns FTestSuiteName. If I do a TestSuit.TestName it returns the FName. This problem seems to be confirmed with the following code: constructor TTestSuite.Create(AClass: TClass; AName: string); begin Create(AClass); FName := AName; end; This is getting very confusing. When are we supposed to use TestSuiteName and when do we use TestName? For example in DUnit you can register a test as follows: RegisterTest(cSuiteNameNonPersistentTests, ATestCaseClass.Suite);

FSuiteName is handled automatically when the TTest descendent is added to a TestSuite, you don't have to set it manually.

Show quoted text 5 lines
So if I want to implement this in FPCUnit, what name am I supposed to set? Maybe I'm just getting confused with the difference between TTest, TTestCase and TTestSuite. I go read some more on this in the DUnit web page (do we have FPCUnit docs explaining this?).

FPCUnit has a different structure then DUnit, is a literal port of the JUnit test framework, with only some changes that were required to adapt the Java code (callbacks instead of inner classes in some places iirc). TTest is an abstract class, TTestSuite is a composite pattern. Just look at the JUnit documentation, here you can find a UML diagram:

http://junit.sourceforge.net/doc/cookstour/cookstour.htm

and there is a good chapter available as an MIT Lecture on OOP and patterns that takes the JUnit framework as a Case Study: http://courses.csail.mit.edu/6.170/old-www/2001-Fall/lectures/lecture-17.pdf

I choose to adhere strictly to the JUnit framework as it was a standard when the FPCUnit port was created, and no additional documentation of the framework was needed (you could always refer to the JUnit documentation and practice, a lot of articles and books were written on the subject).

Still, it's not a good excuse for lack of documentation :)

Regards,
Dean

Reply by email

Graeme Geldenhuys
to Dean Zobec
Dean Zobec wrote
The ATest parameter can be a TTestCase or a TTestSuite

After reading some more docs on DUnit (which is also a port of JUnit) I found they implemented the Composite pattern. Looking a bit closer to the FPCUnit code I came to the same conclusion whith explains a bit more...

Show quoted text 5 lines
> For example in DUnit you can register a test as follows: > RegisterTest(cSuiteNameNonPersistentTests, ATestCaseClass.Suite); FSuiteName is handled automatically when the TTest descendent is added to a TestSuite, you don't have to set it manually.

Looking into the DUnit code I found the reason for passing in the name. It's actually a Suite Path used to automatically create TTestSuites for you so you can better group you tests case in a hierarchy. You would use it if you don't want the registered test case to appear in a top level node (like in the GUI Runner).

I have implemented the same functionality for FPCUnit (a overloaded RegisterTest method) today. See my other message to this mailing list. I'll create a patch for it tomorrow and see if it will make it into 2.2 branch but I doubt - which will be a pitty as it is very useful and helps a lot in a huge test suite like tiOPF has.

FPCUnit has a different structure then DUnit, is a literal port of the JUnit test framework, with only some changes that were required to adapt

DUnit is also based on JUnit. They just followed the path using Interfaces instead of abstract classes. In the end they are very similar I think.

TTest is an abstract class, TTestSuite is a composite pattern. Just look at the JUnit documentation, here you can find a UML diagram:

Thanks, I'll take a look at those links. I'm sure they will come in handy.

Still, it's not a good excuse for lack of documentation :)

I won't tell anyone if you don't! ;-)

Graeme Geldenhuys General error, hit any user to continue.

Reply by email

Michael Van Canneyt
to Graeme Geldenhuys
Graeme Geldenhuys wrote 9 lines
> TTest is an abstract class, TTestSuite is a composite pattern. Just look > at the JUnit documentation, here you can find a UML diagram: Thanks, I'll take a look at those links. I'm sure they will come in handy. > > Still, it's not a good excuse for lack of documentation :) I won't tell anyone if you don't! ;-)

Well,

The good news is that fpcunit is scheduled for documentation after fcl-base and before fcl-db. The bad news is that there are still 12 units to be documented in fcl-base. Which is about 1/3 of the total number of units in fcl-base.

We'll get there. Slowly but surely.

Michael.

Reply by email

Dean Zobec
to Graeme Geldenhuys: After reading some more docs on DUnit (which is also a port of JUnit) I found they…

Graeme Geldenhuys pravi:

Show quoted text 5 lines
Looking into the DUnit code I found the reason for passing in the name. It's actually a Suite Path used to automatically create TTestSuites for you so you can better group you tests case in a hierarchy. You would use it if you don't want the registered test case to appear in a top level node (like in the GUI Runner).

Yes, the registration unit in FPCUnit is very simple, I've actually included it as an example on how to add the test suites more than a set of utility classes. In fact you get the root test suite through GetTestRegistry function and then you add any hierarchy you wish just by creating other suites and building the tree. So your unit is very handy for this and spares some typing.

Show quoted text 6 lines
I have implemented the same functionality for FPCUnit (a overloaded RegisterTest method) today. See my other message to this mailing list. I'll create a patch for it tomorrow and see if it will make it into 2.2 branch but I doubt - which will be a pitty as it is very useful and helps a lot in a huge test suite like tiOPF has.

Yes, if it wasn't for your huge test suite, FPCUnit would not have been improved. The first time I've heard from you, some two years ago I didn't even believe it could handle such a suite gracefully. There is still many improvements that can be made, but my spare time is quite scarce lately. I'm waiting for my vacations :)

DUnit is also based on JUnit. They just followed the path using Interfaces instead of abstract classes. In the end they are very similar I think.

I agree, the differences are not many, and not important, except for the assert methods that are class methods in JUnit and FPCUnit.

Show quoted text 5 lines
> TTest is an abstract class, TTestSuite is a composite pattern. Just look > at the JUnit documentation, here you can find a UML diagram: Thanks, I'll take a look at those links. I'm sure they will come in handy.

You need them if you want to understand the internals. JUnit is a live demonstration that flexibility in OOP design leads to code that is very difficult to understand, due to the many indirections. But I guess in this case it's justified by the fact that the framework had to be also easy to use and had to spare on typing by the end user. Only when I wrote myself the framework in pascal, following the java code, I was able to understand it completely (and still I'm convinced that after so much refactoring on the junit side, some indirections were redundant).

regards,
Dean

Reply by email

Dean Zobec
to Michael Van Canneyt: The good news is that fpcunit is scheduled for documentation after fcl-base and before…

Michael Van Canneyt pravi:

Show quoted text 7 lines
The good news is that fpcunit is scheduled for documentation after fcl-base and before fcl-db. The bad news is that there are still 12 units to be documented in fcl-base. Which is about 1/3 of the total number of units in fcl-base. We'll get there. Slowly but surely.

I had no doubt.
It's a good news for me, as there's still hope I'll be able to help then! :) Thank you,
Dean

Reply by email

Graeme Geldenhuys
to Dean Zobec: Graeme Geldenhuys pravi: Yes, the registration unit in FPCUnit is very simple, I've…
Dean Zobec wrote
creating other suites and building the tree. So your unit is very handy for this and spares some typing.

Yeah, I have now grouped the tiOPF tests into the following suites. Non-Persistent Tests and then one testsuite per registered persistant layer (like CSV, TAB, Oracle, Firebird, etc).

I've done the same for our commercial apps. Splitting the Non-Persistent tests from the Persistant (DB tests). This allows me to run the Non-Persistent suite all at once without having to pull in the slower running DB tests.

Yes, if it wasn't for your huge test suite, FPCUnit would not have been improved. The first time I've heard from you, some two years ago I didn't even believe it could handle such a suite gracefully.

Wow, that long ago.... Time flies when you are having fun. :-)

There is still many improvements that can be made, but my spare time is quite scarce lately. I'm waiting for my vacations :)

Yeah, I have a few more improvements on my list as well... All in due time.

Only when I wrote myself the framework in pascal, following the java code, I was able to understand it completely (and still I'm convinced

I was actually thinking of doing this as an example of Test Driven Development. Writing a new testing framework in Object Pascal, not as a replacement of FPCUnit, but to following the book of Kent Beck. I've done the money example a million times... :-)

Graeme Geldenhuys General error, hit any user to continue.

Reply by email