mocking

How can I mock Moose objects?

What strategies have Perl people used when mocking Moose objects that they will inject into other Moose objects as type-constrained attributes? Test::MockObject::Extends doesn't seem to play well with Moose. I need the object to blessed as a specific package though so a vanilla Test::MockObject won't work. I'm sure other folks have had ...

.Net mocking framework to capture method parameter and examine it latter?

Is there some .Net mocking framework that allows to capture the actual parameter passed to method to examine it latter? Desired code: var foo = Mock<Foo>(); var service = Mock<IService>(); service.Expect(s => s.Create(foo)); service.Create(new Foo { Currency = "USD" }); Assert(foo.Object.Currency == "USD"); Or a bit more complex exam...

How can I mock Assembly?

Is it possible to mock the Assembly class? If so, using what framework, and how? If not, how would do go about writing tests for code that uses Assembly? ...

RhinoMock vs. TypeMock vs. NUnit's Mocking?

I am just starting to do Test Driven Development, and I am wondering the major differences between RhinoMock, TypeMock, and NUnit's built-in mocking? Any information would be greatly appreciated! ...

Mocking USB input

Our product includes some custom hardware, that connects to a PC via USB. We've started looking into automatic testing, but so far I'm unable to find a tool that can record/replay generic USB input. Does anyone know of such a tool? (And - it would be best if it's somehow scriptable - testing would have to alternate between GUI interac...

Unit Testing, Linq to SQL and working around the Data Context

Hi guys I have been looking at the following and it would appear that there are great benefits to be gained by using compiled queries... http://blogs.msdn.com/ricom/archive/2008/01/14/performance-quiz-13-linq-to-sql-compiled-query-cost-solution.aspx My problem is that I want to unit test my queries, but compiled queries need a concre...

How to mock a static variable in java using JMock

Hello, I have a Unit testing problem where a class has a static variable which wants to load the Spring Application Ctx. This class DOES NOT come out of the Bean Factory and I cannot change this fact. static ApplicationContext applicationContext = ...; This works fine, but is hard to JMock, or atleast I don't know a way and until I...

should the DTO objetcs be mocked while testing controllers ?

Its known that DTO doesnt have methods. Since the controller uses the DTO objects , there is a dependency . should we set expectaions on the properties of DTO(mock DTO properties) while testing the controllers.? thanks ...

learning resources for mockito please..

i am required to use mockito to create unit testing framework for existing code. I am unable to find a good place to get started with learning Mockito. Could you please point me to a good learning resource for mockito? (online resource or otherwise) ...

what are the advantages of mocha over rspec's built in mocking framework?

I notice that a lot of people prefer mocha over rspec's built in mocking framework. Can someone explain the advantages of mocha, or any alternative, over rspec's built in mocking framework? ...

How can I test Perl applications using a changing system time?

I have a web application that I want to run some system tests on, and in order to do that I'm going to need to move the system time around. The application used DateTime all the way through. Has anyone got any recommendations for how to change the time that DateTime->now reports? The only thing that comes to mind is subclassing DateTi...

Why Create Mock Objects?

During a recent interview I was asked why one would want to create mock objects. My answer went something like, "Take a database--if you're writing test code, you may not want that test hooked up live to the production database where actual operations will be performed." Judging by response, my answer clearly was not what the interview...

How do you design a C++ application so that Mock Objects are easiest to use?

I've never developed using Test Driven Development, and I've never used Mock Objects for unit testing. I've always unit tested simple objects that don't incorporate other aspects of the application, and then moved on to less simple objects that only reference objects that have already been unit tested. This tends to progress until the f...

List of Mock (Moq) objects - best practices/simplification.

Consider the following: new SUT(null, null, new List<IObjectBeingMocked>() { mockObjectOne.Object, mockObjectTwo.Object }) My SUT (System Under Test) needs a list of objects as the third parameter. These need to be mocks as I've set some expectatioins on these. How would I clear it up so that I can remove the need to call .Object on ...

Mocking DbProviderFactory

I am relatively new to unit testing, and completely new to mocking. I have a database class that wraps the DbProvider factory that I would like to create unit tests for without connecting to the database. How would I mock the DbProvider factory, so I could pass it in to test my class? Would I also need to mock the DbConnection, DbCo...

Mocking a DataServiceQuery<TElement>

How can I mock a DataServiceQuery for unit testing purpose? Long Details follow: Imagine an ASP.NET MVC application, where the controller talks to an ADO.NET DataService that encapsulates the storage of our models (for example sake we'll be reading a list of Customers). With a reference to the service, we get a generated class inheritin...

Is it possible to divert a module in python? (ResourceX diverted to ResourceXSimulated)

I want to simulate MyApp that imports a module (ResourceX) which requires a resource that is not available at the time and will not work. A solution for this is to make and import a mock module of ResourceX (named ResourceXSimulated) and divert it to MyApp as ResourceX. I want to do this in order to avoid breaking a lot of code and get...

GWT Mockito integration

I'm trying to set up and use Mockito into a GWT project, and I'm having trouble using it on the client side (in javascript). I tried to add a module and include Mockito, but it seems not to work (lots of errors). I also tried to do a full checkout from svn and integrate GWT in it that way, the same errors. How should this be done? Thanks...

How do I mock the HttpContext in ASP.NET MVC using MOQ?

[TestMethod] public void Home_Message_Display_Unknown_User_when_coockie_does_not_exist() { var context = new Mock<HttpContextBase>(); var request = new Mock<HttpRequestBase>(); context .Setup(c => c.Request) .Returns(request.Object); HomeController controller = new HomeC...

How to Bypass HTTPContext Usage .?

var mockedService = new Mock(); mockedService.Setup(x => x.InterfaceMethod(args)).Returns(value); _Service = mockedService.Object; MyController controller =new MyController(_Service); var result = (ViewResult)controller.Foo(); Now this Foo() Method contains the Following API Call HttpContext.GetGlobalResourceObject(...,...