NUnit's Action Attribute
Today I discovered NUnit's "Action Attribute". It really helps to clean up test code if you have multiple tests which share a common behavior.
Given you have integration tests which need to store some files to a temporary directory. Each of these tests needs to setup a temp directory and delete it during teardown. NUnit actions allow to seperate this setup/teardown behavior without the need for evil inheritance.
The following Gist shows how it is solved. Just implement ITempDirectoryTest in your test class. That's all (see DemoTest). The Attribute implementation is shown in TempDirectoryAwareActionAttribute.
Written by Markus Reinhardt
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Nunit
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#