Home / Posts tagged "Mocking"

Ask a geek: mocking third party service in Selenium tests of an MVC application

We received the following Ask-a-geek question from Patrick:

I have the following scenario. MVC Application using Ninject and Moq for the unit tests.

We do some additional Tests using Selenium which testes JS etc. So the scenario we want to test is, that in a TestMethod we start IIS Express with the MVC project. Start selenium and do the clicks, check the results. That works all perfect.
Now we have a call to a third party webservice from our repository. In our unittests we used MOQ to mock that. In the Selenium test we want also to mock it. Currently we have this solution
– MVC web.config has a setting, in case that setting is available, we load inject a test repository containg the moq logic. So that means, when we start the test, MVC sees the new setting and instead of injecting the default repository we have the moq repository.

So far, all works good. But here the concerns
– not a nice solution, as all the moq is part for the productive solution
– Moq and testclass are seperated: the whole logic for the Moq is within the MVC solution (repositories) and not part of the Test-Project

Any ideas/suggestions/approches to have a nicer solution?

Continue reading

FakeItEasy and Windows Store Apps are becoming friends

Probably you already know it: The new Windows Store App class libraries prevent proxy generating using frameworks like Castle.Core because System.Reflection.Emit namespace is missing in the limited framework they’re using.

But we still want to do TDD and therefore we need a nice mocking framework, like FakeItEasy, don’t we?

In this blog post I will show you the best way I came up with to develop Windows Store App compatible code with TDD.
Continue reading

Mocking Kata – Instrument Processor (.NET)

We use Coding Katas in Coding Dojos to improve our programming skills. This includes skills in software design, refactoring, Test Driven Development, Mocking, tool usage and a lot of other tiny stuff.

However, I found only a few Katas, especially Katas including the need for mocks (see for example http://codingkata.org/). Most Katas are very algorithmic, which is good for learning TDD. But its bad for learning how to use mocks.

Therefore, I started to invent my own Mocking Katas. I use these in my training courses on Test Driven Development.

Continue reading

Moq suggestions: SetupSequentials

I must say I’m really a huge fan of Moq. Moq is steady growing and the developer community is quite impressive in inventing new features and extensions. I recently ran over a nice feature suggestion placed in a private branch from moq. The branch belongs to Brian J. Cardiff. I suggest you check also his blog out! The feature brain suggested is an extension method which allows to do sequential setups. The sequential setup allows to specify in a fluent way for example different return types on a mock for each call. Let’s have an example!

Continue reading

Mocking Adventures with NMock2: Stubs Advanced

NMock2 is a library for assisting test driven development of .NET code by providing a dynamic mock object creation framework.

In my last post on NMock2, I introduced the new Stub feature of NMock2 and its basic usage. In the second part, we are going to have a look at the advanced possibilities of the Stub mock style:

  • Define Mock Style Of Nested Mocks
  • Define Default Values

Continue reading

NMock2 Documentation Now On MediaWiki

Due to changes on sourceforge.net and its hosted applications, the documentation of NMock2 – a library for assisting test driven development of .NET code by providing a dynamic Mock Object framework for .NET interfaces and classes (virtual and abstract members of classes) – has been moved from WikiSpaces to MediaWiki.

You can check it out at http://sourceforge.net/apps/mediawiki/nmock2/index.php?title=Main_Page

Mocking Adventures with NMock2: Stubs

NMock2 is a library for assisting test driven development of .NET code by providing a dynamic mock object creation framework.

In this article, I’m going to show you the basics of the new stub feature in NMock2. Note that this feature is currently only available on the development trunk in the subversion repository at https://nmock2.svn.sourceforge.net/svnroot/nmock2/trunk. Therefore, the features discussed here may change for the next official release.

Stubs can be used in scenarios where you have to test an instance of a class (let’s call this object testee) and this testee makes calls to another object (dependency) but you simply do not care what the testee calls on the dependency because it is not relevant for your test case.

Stubs will simply ignore any calls to it and if the call has a return value then the stub provides a default value.

Continue reading