How have I to add a new attribute to a custom attribute set?

How to create an attribute and add it to an attribute set programmatically? (an example from the unit tests)