I'm wondering what the best way to do this is... I'm interested in introducing PostSharp into one of my projects, but I'm not sure how to unit test classes marked with an attribute properly.
For example:
public class hello {
[MyAspectThatDoesSomethingToTheDatabaseWhenThisMethodGetsCalled]
public int omg(string lol) {
//fancy logic in here
}
}
I'd like to test the logic in the omg() method, but in the unit tests I need to make sure that the aspect doesn't get called, because there isn't really a database.
Thoughts?
Unit testing is a software development process in which the smallest testable parts of an application, called units, are individually and independently scrutinized for proper operation. This testing methodology is done during the development process by the software developers and sometimes QA staff.
Unit Testing is done during the development (coding phase) of an application by the developers. Unit Tests isolate a section of code and verify its correctness. A unit may be an individual function, method, procedure, module, or object.
The term "implementation" means converting software design into computer programs and computer databases. If a CSCI is developed in multiple builds, software implementation and unit testing of that CSCI will not be completed until the final build.
I'm not entirely sure how postsharp works, but as I currently understand, you invoke a post build process to weave the aspects into the IL.
If my understanding is correct and if you can skip the post-build weaving then you should be testing your method in ignorance of the aspect ( and testing the aspect separately somewhere else ).
Why?
If you test the aspect and the method, you are testing 3 things at once:
This is bad karma and may lead you down the rabbit hole if something goes wrong ( as well as making your unit test into an integration test ).
Looking at the list above:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With