mocking

Why do we need mocking frameworks like Easymock , JMock or Mockito?

Hi, We use hand written stubs in our unit tests and I'm exploring the need for a Mock framework like EasyMock or Mockito in our project. I do not find a compelling reason for switching to Mocking frameworks from hand written stubs. Can anyone please answer why one would opt for mocking frameworks when they are already doing unit tests...

When is it appropriate to do interaction based testing as opposed to state based testing?

Hi, When I use Easymock(or a similar mocking framework) to implement my unit tests, I'm forced to do interaction-based testing (as I don't get to assert on the state of my dependencies. Or am I mistaken?). On the other hand if I use a hand written stub (instead of using easymock) I can implement state based testing. I'm quite unclea...

Loading .eml files into javax.mail.Messages

I'm trying to unit test a method which processes javax.mail.Message instances. I am writing a converter to change emails which arrive in different formats and are then converted into a consistent internal format (MyMessage). This conversion will usually depend on the from-address or reply-address of the email, and the parts of the emai...

How to Fake a AsyncToken return in ActionScript 3

Using Parsley, I have a service that I access through a [Command(selector='list')] public function getRssFeed( msg:RssEvent ):AsyncToken { return service.list() as AsyncToken; } when I point to the "Real" RssService, everything works as expected. My problem is when I point to the "Mock" RssService. I can't figure out how to fake a Async...

Mock Objects properties not changing

I am new to using Mock test in .Net. I am testing out a financial transaction which is of the following nature: int amt =20; //sets all the props and func and returns a FinaceAccount. //Note I did not SetUp the amt of the account. var account =GetFinanceAccount() //service layer to be tested _financeService.tranx(account,amt); //ch...

Unit testing, mocking - simple case: Service - Repository

Consider a following chunk of service: public class ProductService : IProductService { private IProductRepository _productRepository; // Some initlization stuff public Product GetProduct(int id) { try { return _productRepository.GetProduct(id); } catch (Exception e) { // log, wrap then throw ...

RSpec - mocking a class method

I'm trying to mock a class method with rspec: lib/db.rb class Db def self.list(options) Db::Payload.list(options) end end lib/db/payload.rb class Db::Payload def self.list(options={}) end end In my spec, I'm trying to setup the expectation Db::Payload.list will be called when I call Db.list: require 'db/payload' d...

Qt, unit testing and mock objects.

Hello. Qt framework has internal support for testing via QtTest package. Unfortunately, i didn't find any facilities in it that can assist in creating mock objects. Qt signals and slots offers a natural way to create a unit-testing friendly units with input (slots) and output (signals). But is it any easy way to test that calling specif...

Creating a Mock DetactedCreteria Object

I have a function in my service layer whose output needs to be mocked. it takes in a FinanceAccount object and returns a List the function uses the FinanceAccount object to create a DetachtedCreteria. and fetch a List. How can I SetUp this function so that it returns separate Lists for 3 three different FinanceAccount objects. I am usi...

Is Entity Framework more mockable than Linq2Sql?

I've found that Linq2Sql doesn't (Rhino) mock well, as the interfaces I need aren't there. Does EF generate code that's more mockable? NOTE: I'm not mocking, yet, without interfaces, the next reader of this question may not have my bias. EDIT: VS2008 / 3.5 for now. ...

Mock Object Data

I'd like to mock up object data, not the objects themselves. In other words, I would like to generate a collection of n objects and pass it into a function which generates random data strings and numbers. Is there anything to do this? Think of it as a Lorem Ipsum for object data. Constraints around numerical ranges etc. are not neces...

When should we use Mockery vs JUnit4Mockery?

If writing a Java unit test with mocking using JMock, should we use Mockery context = new Mockery() or Mockery context = new JUnit4Mockery() What is the difference between the two, and when should we use which? ...

Is Google Mock a good mocking framework ?

I am pioneering unit testing efforts at my company, and need need to choose a mocking framework to use. I have never used a mocking framework before. We have already chosen Google Test, so using Google Mock would be nice. However, my initial impressions after looking at Google Mock's tutorial are: The need for re-declaring each method ...

phpUnit - mock php extended exception object

I'm testing some legacy code that extends the default php exception object. This code prints out a custom HTML error message. I would like to mock this exception object in such a way that when the tested code generates an exception it will just echo the basic message instead of giving me the whole HTML message. I cannot figure out a w...

How to keep your unit tests simple and isolated and still guarantee DDD invariants ?

DDD recommends that the domain objects should be in a valid state at any time. Aggregate roots are responsible for guaranteeing the invariants and Factories for assembling objects with all the required parts so that they are initialized in a valid state. However this seems to complicate the task of creating simple, isolated unit tests a...

AutoFixture vs NBuilder

Hello all, I'm seleting tool for populating my .net models (poco) with test data. I'm actually mocking wcf services and need to populate datacontract objects with test data. Found a huge number of test data generation tools, but the majority is realted to DB test data generation and don't fit well for .net objects creatiom. The most a...

RSpec mocking a nested model in Rails - ActionController problem

Hi All I am having a problem in RSpec when my mock object is asked for a URL by the ActionController. The URL is a Mock one and not a correct resource URL. I am running RSpec 1.3.0 and Rails 2.3.5 Basically I have two models. Where a subject has many notes. class Subject < ActiveRecord::Base validates_presence_of :title has_many...

Cannot mock class with constructor having array parameter using Rhino Mocks

Hi, We cannot mock his class in RhinoMocks. public class Service { public Service(Command[] commands){} } public abstract class Command {} // Code var mock = MockRepository.GenerateMock<Service>(new Command[]{}); // or mock = MockRepository.GenerateMock<Service>(null) Rhino mocks fails complaining that it cannot find a construct...

Unit testing with JMS (ActiveMQ)

How to do unit testing with JMS ? Is it some de-facto for this ? I googled something - Unit testing for JMS: http://activemq.apache.org/how-to-unit-test-jms-code.html - jmsTemplate: activemq.apache.org/jmstemplate-gotchas.html - mockRunner : mockrunner.sourceforge.net/ Do you have any good experience on those and suggestion for me ? ...

How do I mock a method with an open array parameter in PascalMock?

I'm currently in the process of getting started with unit testing and mocking for good and I stumbled over the following method that I can't seem to fabricate a working mock implementation for: function GetInstance(const AIID: TGUID; out AInstance; const AArgs: array of const; ...