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
11
votes
2 answers

Import a pyi (type stub file) into a normal python module

I have a program (like a macro) that runs within a parent program and imports an API module from that program (lets call it foo). The problem is that that module only exists within that program, so I can't do things like run pydocmd outside the…
Ian
  • 5,704
  • 6
  • 40
  • 72
11
votes
2 answers

sinon - create stub that returns own arguments

How can I make a stub that returns it's own arguments, like so: var stub = sinon.stub().returns(???); var result = stub('foo'); //result = foo This will be nested so I can't return nothing and then check stub.getCall...
Mankind1023
  • 7,198
  • 16
  • 56
  • 86
11
votes
2 answers

sinon.js stub - can you call more than one callback on a single stubbed function?

If I have a stub for a function that takes 2 callbacks, how can I wire up sinon.js to call both callbacks when the stubbed function is invoked? For example - here's function that I want to stub which takes 2 functions as arguments: function…
serg10
  • 31,923
  • 16
  • 73
  • 94
11
votes
7 answers

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…
11
votes
9 answers

Parsing C++ to generate unit test stubs

I've recently been trying to create units tests for some legacy code. I've been taking the approach of using the linker to show me which functions cause link errors, greping the source to find the definition and creating a stub from that. Is there…
Dave Hillier
  • 18,105
  • 9
  • 43
  • 87
11
votes
1 answer

Stub vs Mock when unit testing

I have lately become very interested in testing and Im now trying to learn to do unit testing in the best way possible. I use NUnit together with Rhino Mocks. I have also been reading a lot over here at Stackoverflow but havent been able to find a…
Daniel Hansen
  • 251
  • 2
  • 3
  • 11
11
votes
1 answer

Can't stub things with Rspec

I have a Rails 4 application, and here is my lib/foobar: jan@rmbp ~/D/r/v/l/foobar> tree . ├── foo_bar.rb └── foobar_spec.rb 0 directories, 2 files And the files: foobar_spec.rb require "spec_helper" describe "FooBar" do subject { FooBar.new } …
if __name__ is None
  • 11,083
  • 17
  • 55
  • 71
11
votes
3 answers

Mockito: Stub method with complex object as a parameter

Maybe this is a newbie question, but can't find the answer. I need to stub a method with Mockito. If the method has "simple" arguments, then I can do it. For example, a find method with two parameters, car color and number of doors: …
Andres_age
  • 175
  • 1
  • 2
  • 9
11
votes
1 answer

Using Moq to Stub an interface method

Possible Duplicate: How to mock a method that returns an int with MOQ Here's my interface: public interface ICalenderService { DateTime Adjust(DateTime dateToAdjust, BusinessDayConvention convention, List holidayCities); …
slandau
  • 23,528
  • 42
  • 122
  • 184
10
votes
3 answers

Cypress: Stub open window

in my app there is an recommendations list, which on click opens a new window with a dynamic address: $window.open(_shopURL, '_blank'); Now I'm trying to stub the windows.open event as shown in…
Flashed
  • 111
  • 1
  • 1
  • 5
10
votes
3 answers

Wiremock query parameter JSON stub file

I'm trying to mock query parameter using a wiremock JSON stub file. It works when I do it this way : { "request": { "method": "GET", "url": "/posts?id=1", }, //... } However when I change my query parameter to use the dedicated field…
Robert jardonneau
  • 434
  • 2
  • 4
  • 14
10
votes
2 answers

Wiremock Stand alone - How to manipulate response with request data

I was trying to implement mocking of POST REST call using Wiremock Standalone server. I am faced with a challenge like this, suppose the post body contains an "name" field and its value, the same value should be returned in the response of that POST…
Sam
  • 181
  • 2
  • 3
  • 13
10
votes
3 answers

Stubbing non-exported function with sinon

I write a unit-test for doB function of my module. I want to stub the function doA without exporting it, I prefer not change the way doB accesses doA. I understand that it cannot be simply stubed because it isnt in the exported object. How do I stub…
agoldis
  • 1,067
  • 16
  • 28
9
votes
4 answers

How to stub a socket in C?

I've written client code that's supposed to send some data through a socket and read back an answer from the remote server. I would like to unit-test that code. The function's signature is something along the lines of: double call_remote(double[]…
lindelof
  • 34,556
  • 31
  • 99
  • 140
9
votes
1 answer

How to mock AWS SDK2 (S3) in Java

So I want to mock AWS SDK 2.x (only S3 service), so that test upload and download files to a bucket without a real AWS. I'm looking for a Java implementations. I found a lot what implements (Adobe S3Mock ...etc), but all of them uses AWS SDK 1.x.
Gábor Csikós
  • 2,787
  • 7
  • 31
  • 57