Sometimes I write tests to ensure that there are all the properties I expect in a class. The test looks like this:

[code language="objc"]
#import <XCTest/XCTest.h>
#import <objc/runtime.h>
#import "MyClass.h"
...
- (void)testThatMyClassHasNameProperty {
objc_property_t nameProperty = class_getProperty([MyClass class], "name");
XCTAssertTrue(nameProperty != NULL, @"MyClass should have a name property.");
}
[/code]

All these tests look the same. What a great opportunity to write a script to create those tests. Here it is:

[code language="perl"]
#!/usr/bin/perl -w

use strict;

if (not defined($ARGV[1])) {
die "usage: $0 <class name> <file with property names>n";
}

open(PROP, $ARGV[1]) || die "could not open property names file: $!n";

my $className = $ARGV[0];
while (defined(my $line = <PROP>)) {
chomp($line);
print "- (void)testThat" . $className . "Has";
print ucfirst($line) . "Property {n";

print "tobjc_property_t " . $line . "Property = class_getProperty([";
print $className . " class], "" . $line . "");n";

print "tXCTAssertTrue(" . $line . "Property != NULL, @"";
print $className . " should have a " . $line . " property.");n}n"
}
[/code]

To print the tests onto the Terminal call the script:
[code]
perl createPropertyTests.pl MyClass properties.txt
[/code]

The `properties.txt` file is expected to look like this:
[code]
name
date
age
[/code]

Any comments? Get in touch with me at [@dasdom](https://alpha.app.net/dasdom).