Unit Testing OData Web API/Entity Framework Applications

Premier Developer

Premier

The cost of fixing bugs is lower if found early in the software development cycle. Unit tests greatly reduce this cost by pushing quality upstream. This helps prevent regression bugs and when coupled with TDD approach, provides a solid foundation for a complete test suite. Furthermore, teams are striving to push code into production more frequently and with higher quality. In order to flourish in this DevOps space, it is imperative to have a pipeline of solid automated tests. Traditionally, unit tests have been written for class library projects or middle tier/business logic projects.

In this blog post, senior Premier Developer consultant Monu Bambroo demonstrates how to easily unit test an OData based Web API service which is consuming data from SQL DB using Entity Framework. The goal is to write unit tests which stub out the actual DB calls. We will make use of faking the DB Context and using a common DI pattern of construction injection. The result is a highly testable maintainable and cohesive codebase.

Continue reading on Monu’s blog
Premier Developer
Premier Developer

Premier Support for Developers

Follow Premier   

No Comments.