Archives
-
Asserting a mock with test framework
When asserting an expected call for its number of occurrences or may be just to verify if the setup/arrange is acted as intended, the tool generally raises assertion that points us to the reason why the test failed. Different mocking tools use different exception classes therefore there is no common way to consolidate them.
-
Future mocking with #IgnoreInstance
In my previous post, i showed how JustMock picks mock expectations based on current context without the instance being injected. Based on feedback we found that It’s sometimes confusing and often does not work as intended. However, the context of this post is not to introduce future mocking rather a new feature that allows you to skip mock instance intentionally (when you can’t pass the dependency through a constructor or via method argument) instead the tool is applying it for you on behalf.
-
Introducing AutoBox - On the fly dependency injection and caching container.
Just when we have dependencies for a controller, we need to wrap around our heads to write a bootstrapper that will dynamically inject dependencies for a controller in runtime and once we we want to do data caching like a particular method in accounts repository need to get cached for a certain number of time and it should invalidate when someone calls update, things get complex and may be we get around this with some attribute based solution.
-
Future mocking revisited
Previously , I have posted how it is possible to mock a method without passing the dependency through a constructor / calling method. This is something true for third party controls and tools where we have little control over how its created.
-
PostSharp and JustMock side by side.
In this post I will show mocking a member call inside a PostSharp aspect. There were previously compatibility issues between both of the tools running side by side which is now been officially fixed with the most recent release of that tool (>= 2.1.2.8-1594). For those who don’t know what PostSharp is all about, it is a tool that lets you write aspects easily than you can imagine.
-
Fake a member without passing the instance via dependency
I have came across this several times in forum (telerik) on how I can really fake an item yet I don’t want to pass the instance as an argument. Ideally, this is not a best design but there are third- partly libraries that you have little control over how its written. Anyway, whatever the case might be. This post will show you how you can achieve the above using JustMock. I will be using MSpec in conjunction for the example.
-
Running JustMock profiler outside of Visual Studio
In this post , I would be focusing on the issue that generally comes to query on how to run JustMock with standalone tools like nunit or msbuild console. Since mocking concrete method works initializing the .net profiler that is set using two variables in the runtime to let JustMock work the correct way.
-
Mocking MsCorlib members
In this post , I will show how you can mock members from MsCorlib. This is more of an introductory post and shows what you need to do in order to successfully mock an MsCorlib member.
-
Mocking constructor
While unit testing a target type, it is likely that the test is failing during object creation because we forgot to include a mandatory configuration file or a line in the constructor is throwing exception because it is making call to some external service or data store which on the other hand requires a little more orchestration to get things going . To better illustrate this, let’s create an entity framework data container either new or from an existing database. Once we have completed the required steps, there will be an entry-point class where we will notice the following default constructor: