[fpc-devel] .NET Reflection vs RTTI

Vincent Snijders vsnijders at quicknet.nl
Wed Nov 21 15:07:31 CET 2007


Micha Nelissen schreef:
> Thorsten Engler wrote:
>> Take a look here to get some idea about the uses for attributes in 
>> just the
>> core framework: http://msdn2.microsoft.com/en-us/library/2e39z096.aspx
> 
> What? Most sounds like poor hacks to get around compiler/linker 
> limitations.
> 
<snip>

> Perhaps there are also useful ones, that do reduce application and 
> framework programmers code significantly?

In c# code I use attributes for the unit test frame work. Unittest are compiled into 
a dll. The unit test runner loads the Dll and considers all classes with the 
[TestFixture] attribute to be classes that contain test methods. All test methods 
have the [Test] attribute. Test methods can also be given an [Ignore] attribrute to 
disable testing it. Or an [Category("LongTest")] attribute with "LongTest" a free 
string parameter to create categories in your test suite, so that you tell the test 
runner to run only a selection of the tests or to skip running them.

The current fpc solution is that you need to register classes with test methods. 
This is an extra action.

For detecting the test methods, the name of published methods is used: if they start 
with 'Test' then it is considered to be a test method. Not more work, but less 
freedom in method name and they tend to be 4 chars longer ...

Creating categories could be done by construction different test suites, but this is 
more awkward then the attributes approach.

The Ignore attribute can be simulated by adding Assert.Ignore as first line in the 
testmethod, but this has as drawback that test setup and test teardown will be 
executed anyway.

All in all, I like the flexibility and the seperation of execution logic (how to 
execute a test in program code) and its meta (what test to execute in the attribute 
declaration) in c#. I think it is more productive.

Vincent





More information about the fpc-devel mailing list