Questions tagged [stub]

A replacement implementation for objects, methods, or functions in order to remove external dependencies, or the object at the client end of an RPC or RMI invocation.

A replacement implementation for object, method, or function. The typical types of stubs are:

  • Testing stubs that remove external dependencies. They are typically used during unit and component testing. If you're trying to write a unit test and need to replace a simple call to a database, external libraries (e.g., file I/O) or other system API, stubbing might be perfectly suited for your needs.
  • RPC (CORBA, RMI, web service) stubs forward the call to remote service where it is handled; the answer, if any, is returned to the calling side. They implement the same interface that is implemented by the servicing object on remote side (may also implement additional interfaces).
  • Dummy stubs are empty placeholders for objects, methods or functions that are supposed to be completed later. They allow the current code to compile so that other, already finished parts could be tested. Such stubs are used when implementing a very large libraries following some already specified API.

A mock is somewhat similar to the testing stub but is not considered stub as it is a special purpose object capable of registering that has been called on it. It does not take other actions (a generally unfavoured partial mock does forwards execution of some methods to underlying object).

1108 questions
5
votes
1 answer

Why use mocha gem if Minitest have stub and Mocks?

I see Minitest provides Mock and stubbing. Then why does somebody use mocha gem for mocking and stubbing? Are Minitest stub and mocks have limitation. If yes then can somebody explain this.
Zia Qamar
  • 1,694
  • 1
  • 15
  • 35
5
votes
3 answers

Using SinonJS stub (with rewire)

I have a function: var publish = function(a, b, c) { main = a + getWriterName(b,c); } and getWriterName is another function: var getWriterName = function(b,c) { return 'Hello World'; } I want to test the "publish" function but I do not…
Samman Bikram Thapa
  • 1,037
  • 12
  • 15
5
votes
1 answer

Adding Security Header

I am trying to generate a security header in a Java Axis2 Client in the below format.
user970500
  • 571
  • 1
  • 7
  • 14
5
votes
2 answers

Spock - returning fixed value not working as expected

I have to begin by apologising if the terms I use are incorrect. I use groovy/java for automation tasks only(Gradle), and I don't have years of experience delivering production grade software. So, the challenge that I have is as follows: I have a…
Sion
  • 395
  • 4
  • 15
5
votes
2 answers

Stubbing a before_filter with RSpec

I'm having trouble understanding why I can't seem to stub this controller method :load_user, since all of my tests fail if I change the actual implementation of :load_user to not return and instance of @user. Can anybody see why my stub…
TheDelChop
  • 7,938
  • 4
  • 48
  • 70
5
votes
1 answer

Stub super method in controller

How to stub :super method from included module. I have following controller: class ImportsController < BaseController include ImportBackend def import_from_file super rescue TransferPreview::Error => exc flash[:error] = "Some…
user2239655
  • 830
  • 2
  • 11
  • 28
5
votes
1 answer

RSpec: Testing that a mailer is called exactly once

I have a Mailer that looks something like this: class EventMailer < BaseMailer def event_added(user_id, event_id) # do stuff and email user about the event end end I'm calling this EventMailer like this from inside the Event class: class…
Philoktetes
  • 220
  • 4
  • 10
5
votes
2 answers

How to use Microsoft Fakes Assemblies on Process.Start

I would like to mock the System.Diagnostics.Process.Start call, so I've added a Fakes Assembly for the System Assembly. The problem is that Start is a static method on System.Diagnostics.Process so I'm not getting a shim to be able to hook a…
5
votes
1 answer

Shimming with Microsoft Fakes and a static, generic method

I need to shim a static generic method for a unit test. However, I can't seem to get Fakes to create the shim object. Does anyone know how to accomplish this? In particular, I want to shim Newtonsoft's JsonConvert.DeserializeObject<>()
Chris
  • 1,690
  • 2
  • 17
  • 24
5
votes
2 answers

Why can't I change the return value in a Rhino Mocks stub object?

Forgive me if this is a stupid question, but I'm fairly new at mocking, and am trying to get my head around it. I have some unit tests (using the built-in Visual Studio 2010 Professional testing features), which use a stub that is needed by a…
Avrohom Yisroel
  • 8,555
  • 8
  • 50
  • 106
5
votes
2 answers

Stub helper method for request spec in rails / rspec

I have a helper method called get_books_from_amazon that does an API call and returns an array of books. I can't figure out how to stub it out in my request specs. module BooksHelper def get_books_from_amazon(search_term) ... end end class…
Tyler
  • 11,272
  • 9
  • 65
  • 105
5
votes
1 answer

RSpec: stub method call for external object inside method

I'm attempting to stub the behavior of a method within a method: class A def method_one(an_argument) begin external_obj = ExternalThing.new result = external_obj.ext_method(an_argument) rescue Exception => e logger.info(e.message) …
Sly
  • 743
  • 13
  • 38
5
votes
1 answer

stub method with block of code as parameter with OCMock

Is there a way to stub method, that takes block as it's parameter? For example mehod: - (void)reverseGeocodeLocation:(CLLocation *)location completionHandler:(CLGeocodeCompletionHandler)completionHandler;
kraag22
  • 3,340
  • 3
  • 29
  • 37
5
votes
1 answer

Unit Test for n tier architecture

I am using 3 tier architecture: Controller, Business, and Data Layer. In my Data Layer, I am making a call to an Sql Server Database by passing Connection String and other necessary parameters. I have to write unit tests for the Controller layer and…
palak mehta
  • 696
  • 4
  • 13
  • 30
4
votes
1 answer

How to stub a method in cucumber?

I want to stub out the space_available_mb method in SubmissionsController so that it returns 5. This doesn't work. It returns the correct space on the real hard disk. if space_available_mb is commented out, an expectation error is thrown, which…
siamii
  • 23,374
  • 28
  • 93
  • 143