mocking

Unit testing my wcf services

I am hoping there is a better way to do this. Do I really have to wrap each method of my wcf service into an interface in order to use it? I don't think my fellow developers are going to buy into this because of the amount of time it takes... there must be a better way! ...

jquery (or pure js) simulate enter key pressed for testing

What the best way to simulate the user pressing "enter"? $(element).keypress() doesn't seem to allow me to pass in the actual key that was pressed. ...

Saving to a repository using Rhino Mocks

Hi, I have so far been coding by doing mostly Get methods in my business/service layer using Rhino Mocks to get an expected List or type and making Rhino Mocks return it for me, my question is how do I test a set/save call, e.g void SaveCustomers(Customer) I have a call called GetCustomers, can I use Rhino mocks to call this immediatel...

Which resource to learn Rhino Mocking frameworks?

I'm very new at mocking and Rhino Mock. I searched for resources about learning Rhino Mocks but not found an easy one. Does anyone knows any good resources to start ...

Mocking none interface classes

Is it true that mocking frameworks in general and Rhino mocking in specific only mocks interfaces and classes that have virtual method? For example can I mock following simple class: public class MyClass { void method1() { //some code goes here } } If the answer is true, why such a limitation exists? Is there any w...

Test if ICommand was executed

Hi, My questions is the following: how can I test if an ICommand's Execute method was called on a mock object ? I'm using the following code: var mockOperandVM = new Mock<UCOperandViewModel> (); mockOperandVM.Setup (x => x.EditCommand).Returns (new RelayCommand<String> (x => { })); var toolbarTrayVM = new UCToolbarTrayViewModel (...

What are the pros and cons of rspec mocking versus other mocking frameworks?

I have seen a lot of outdated podcasts that mention mocha as a gem I would want to install because it does mocking better then rspec. I have a feeling that the rspec developers have caught on to this and have improved their mocking since then. However, in the default spec_helper.rb file I see some commented out code stubs for three mocki...

rspec mock_model model never restored

I'm using rspec 1.3, and using rspec's mock_model to mock out some of the models in my controller tests. I create all the mocks in the before(:each) in the controller spec. I then run my model tests where I build real activerecord objects for setup in before(:each) instead of mocks. It seems that in my model tests, the model is still ...

How can I override a specific Seam component?

I have been mocking out some seam components using the following signature: @Name("myService") @Install(debug = true, precedence = Install.MOCK) public class MyServiceMock implements MyService I enable my mocks by changing this line in my components.xml <core:init transaction-management-enabled="false" /> to this: <core:init tran...

PHPUnit - creating Mock objects to act as stubs for properties

hi all I'm trying to configure a Mock object in PHPunit to return values for different properties (that are accessed using the __get function) Example: class OriginalObject { public function __get($name){ switch($name) case "ParameterA": return "ValueA"; case "ParameterB": return "ValueB"; } } I'm trying to mock this using: ...

Java Instantiate Abstract Class or Partially Implemented Interface

I have an interface that has about 20 methods (huge). I want to create a single instance for testing purposes, but I only need to override one method. What's a good way to get an instance of this class with the overridden method without having to define the whole class with a tone of "//TODO: implement this" methods. Mocking frameworks...

Is the use of mocks a good programming practice or just a different way to do it?

Would you guys say that the use of mocks is better than not using mocks? Is mocking used only in unit testing or could it be used directly in the original project as the real object and switch it after? I've been reading here and there and the most attractive thing about mocking I found was the layer isolation. ...

Rhino Mocks mocking WindowsImpersonationContext

Is it possible to use Rhino Mocks to mock WindowsImpersonationContext? I get: System.MissingMethodException : Can't find a constructor with matching arguments ----> System.MissingMethodException : Constructor on type 'WindowsImpersonationContextProxy04bee852de914d5b8a47d6776edc4cb3' var windowsImpersonationContext = mockRepository....

Mocking library/framework that works best in Android?

I'm developing Android application using third party libraries (Twitter4j). I want to be able mock those objects (also objects created by me) in JUnit and functional tests. Do you have any good experiences using some mocking libraries and you can recommend them? ...

How to mock PreferenceManager in Android?

I've written a class that is using Context, third party library and SharedPreferences from PreferenceManager. It's possible to mock Context, third party library can be mocked using some mocking framework, but what to do with PreferenceManager? I have two methods: public void saveString(ThirdPartyObject obj) { SharedPrefer...

How to prevent a call to the data layer from a mocked object

I have a business object that I am mocking (using Moq) for business tests. When I call the object, it calls another business object which goes to the data layer. I can set a return to calls within the object that I wrote, but how can I prevent it from calling the other object and going into the data layer? Is there a standard practice f...

Which style exists for mocking with Rhino?

I heard that latest style is AAA. Is there any other one? Why we use one and don't use another? ...

PHPUnit "Mocked method does not exist." when using $mock->expects($this->at(...))

I've run into a strange issue with PHPUnit mock objects. I have a method that should be called twice, so I'm using the "at" matcher. This works for the first time the method is called, but for some reason, the second time it's called, I get "Mocked method does not exist.". I've used the "at" matcher before and have never run into this. ...

Where do I put my mocks?

Hi I'm struggling to get mocks working, for a change, and was wondering where people generally put their mock classes. I seem to have three basic choices none of which seem to work. I can put them in with the application assembly itself, in which case they ship with the application, which seems bad, but they are available for unit te...

Mocking EventLog and EventLogEntry

I'm trying to write unit tests for an application that reports on Entries in an EventLog. Right now when I run the unit tests, I'm having to create a temporary EventLog, write entries to it, and delete the log when I'm done. I'm doing this because I need to get back the EventLogEntry object, which have no constructor. My question is...