mocking

mocha and nested objects

Excuse if this is a silly question, I am new to mocking. I am able to use mocha to do things like: person.expects(:first_name).returns('David') How can I mock a nested object? Say I have a Product that belongs to a Person and I want to get the first name of that person. In my app I might do it like this: product.person.first_name ...

Rhino Mocks stubs and mocks are only good for interfaces?

Is it correct that Rhino Mocks stubs and mocks are only good for interfaces, not concrete classes? I spent quite a time trying to make this piece of code working. What I did not expected is that stabbed pubSubClient will always call Send method from the class. That method has some dependencies and throws exception. [Test] public void Te...

Moq (or possibly another framework) on Mono / MonoTouch

I've just started some MonoTouch development and I've tried, and failed, to get Moq working for my unit tests. The binary version fails because it's looking for System v2.0, which I assume is down to its Castle requirements, and building it from source crashes the compiler! My question is has anyone gotten Moq to work on Mono (the touch...

How to mock construction of new objects under JDK 1.4?

Hi! I'll looking about mocking of constructor calls in tested method. Something like http://code.google.com/p/powermock/wiki/MockConstructor The problem is that I'm working under JDK 1.4 (this is requirement of customer). I tried to use Retrotranslator for PowerMock, but it seems that I can do nothing about required use of annotations @...

Is HttpContextWrapper all that....useful?

I've been going through the process of cleaning up our controller code to make each action as testable. Generally speaking, this hasn't been too difficult--where we have opportunity to use a fixed object, like say FormsAuthentication, we generally introduce some form of wrapper as appropriate and be on our merry way. For reasons not pa...

not using partial mocking? do they also mean in web-app?

Im learning Mockito and in chapter 16 they say you should not use partial mocking in new system. I disagree, for example in one of my actions i use partial mocking for static framework methods, sql calls, etc. I extracted the stuff into methods and then mock it in tests. Most of those methods are specific to this action and wont be call...

How to set a variable within a mock object

Is there any way to set a class level variable within a mock object? I have the mock object set similar to this: $stub = $this->getMock('SokmeClass', array('method')); $stub->expects($this->once()) ->method('method') ->with($this->equalTo($arg1)); Win the real class there is a variable that needs to be set for it to...

C++ Mock/Test boost::asio::io_stream - based Asynch Handler

I've recently returned to C/C++ after years of C#. During those years I've found the value of Mocking and Unit testing. Finding resources for Mocks and Units tests in C# is trivial. WRT Mocking, not so much with C++. I would like some guidance on what others do to mock and test Asynch io_service handlers with boost. For instance, in ...

Moq + VB.NET - will it be fully supported in VS2010 automatically in its current form?

Hello, We are looking to make a final decision on our Mocking framework. After trying several, I have fallen in love with Moq. I also love TypeMock - but because we are in the early stages of implementing TDD across the team, we do not want to make such a large investment quite yet. We are using VS 2008 now and are going to move to 2010...

Unit testing an MVC action method with a Cache dependency?

I’m relatively new to testing and MVC and came across a sticking point today. I’m attempting to test an action method that has a dependency on HttpContext.Current.Cache and wanted to know the best practice for achieving the “low coupling” to allow for easy testing. Here's what I've got so far... public class CacheHandler : ICacheHan...

Python library for creating stubs/fake objects

I am looking for python stubbing library. Something that could be used to create fake classes/methods in my unit tests.. Is there a simple way to achieve it in python.. Thanks PS: I am not looking for mocking library where you would record and replay expectation. Difference between mock and stubs ...

When should I stub out a type by manually creating a "stub" version, rather than using a mocking framework

Are there any circumstances where it is favourable to manually create a stub type, as opposed to using a mocking framework (such as Rhino Mocks) at the point of test. We take both these approaches in our projects. My gut feel when I look at the long list of stub versions of objects is that it will add maintenance overhead, and moves the...

Anyone using Moles / Pex in production?

Hi all, I did search the forum and did not find a similar question. I'm looking to make a final decision on our mocking framework of choice moving forward as a best practice - I've decided on Moq... untill I just recently discovered MS has finally created a mocking framework called Moles which seems to work similar to TypeMock via the p...

Is unit testing the definition of an interface necessary?

I have occasionally heard or read about people asserting their interfaces in a unit test. I don't mean mocking an interface for use in another type's test, but specifically creating a test to accompany the interface. Consider this ultra-lame and off-the-cuff example: public interface IDoSomething { string DoSomething(); } and the...

AutoMockContainer with support for automocking class-instances

I have a constructor which has a non-interface dependency: public MainWindowViewModel(IWorkItemProvider workItemProvider, WeekNavigatorViewModel weekNavigator) I am using the Moq.Contrib automockcontainer. If I try to automock the MainWindowViewModel class, I get an error due to the WeekNavigatorViewModel dependency. Are there any a...

Moq - How to mock a function call on a concrete object?

Hello, How can I do this in Moq? Foo bar = new Foo(); Fake(bar.PrivateGetter).Return('whatever value') It seems I can only find how to mock an object that was created via the framework. I want to mock just a single method/property on a concrete object I've created... In TypeMock, I would just do Isolate.WhenCalled(bar.PrivateGetter...

Mock versus Implementation. How to share both approaches in a single Test class ?

Hi, See the following Mock Test by using Spring/Spring-MVC public class OrderTest { // SimpleFormController private OrderController controller; private OrderService service; private MockHttpServletRequest request; @BeforeMethod public void setUp() { request = new MockHttpServletRequest(); re...

Downsides to using FakeWeb compared to writing mocks for testing

I never liked writing mocks and a while ago someone here recommended to use FakeWeb. I immediately fell completely in love with FakeWeb. However, I have to wonder if there is a downside to using FakeWeb. It seems like mocks are still much more common, so I wonder what I am missing that's wrong with using FakeWeb instead. Is there a certa...

Trouble mocking on cucumber + rails

I'm having a lot of trouble trying to define a mock for a rails models on cucumber. It seems like the method is creating a bunch of message expectations and i keep getting errors like these: Given I have only a product named "Sushi de Pato" # features/step_definitions/product_ steps.rb:19 unexpected invocation: #<Mock:ProductCate...

Mocking ImportError in Python

I'm trying this for almost two hours now, without any luck. I have a module that looks like this: try: from zope.component import queryUtility # and things like this except ImportError: # do some fallback operations <-- how to test this? Later in the code: try: queryUtility(foo) except NameError: # do some fallback ...