Unit Testing and Dependancy Injection, with xUnit InlineData and Unity

added by tdupont
10/20/2013 11:10:44 PM

458 Views

Inversion of control is great because it makes your code more testable; but you usually still have to write tests for each implementation of your interfaces. So what if your unit testing framework could just work directly with your container to make testing even easier? Well, xUnit can! Below we define a custom data source for our xUnit theories by extending the InlineDataAttribute. This allows our data driven unit tests to resolve types via a container, and then inject those resolved objects straight into our unit tests. Bottom line: This allows us to test more with less code!


0 comments