A mocking framework is used to create replacement objects. These objects can be Fakes, Stubs, and Mocks. In unit testing scenarios, developers use mocking frameworks to isolate dependencies. This allows for a quick, concise, and reliable way to ensure that the testing goes smoothly.
More Background on Using Mocking Frameworks
Like discussed above, mock frameworks are extensions testing techniques for object oriented programming. So what problem does it solve? Let’s find out.
Say that you are testing your code that is still in development. In order to achieve the right results, you need to test its interactions with system resources, outside applications, and other dependencies. Unfortunately, you learn early on that that is not possible. Utilizing a mock framework allows for realistic emulations of the required interactions.
Creating a Mock
When you are running a test, they have to be set up. Oftentimes, dependencies are still under development and can require a set response, ie., a specific time of day, or error code. Even when you feel good that the code is interacting with external program or different system components, the tests can cannot be counted on.
With mock, they interact with the code as interfaces, meaning that you must write a fully-interface compliant test. When this is done properly, the code will not be able to tell the difference between the mock and the actual object.
Need a visual? Check out this Pluralsight video on how to Create mock objects with .NET
So, should you start mocking frameworks for testing? The answer to that is totally up to you. It matters what you are testing and how in depth of an interaction you are looking to get. Mindfire Technology loves looking at different ways to make writing and testing code more efficiently. Ask us what cool new tech we are working on, and we will answer!
For the .NET Newbie Podcasts list, the entries must fit certain criteria. First off, they must talk about .NET and issues surrounding it. Secondly, it only makes sense for developers and programmers that use that platform to share their opinions. Lastly, it must satisfy your inner geek.