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

Fast (Rspec) tests with and without Rails

I have two classes: 1.Sale is a subclass of ActiveRecord; its job is to persist sales data to the database. class Sale < ActiveRecord::Base def self.total_for_duration(start_date, end_date) self.count(conditions: {date: start_date..end_date}) …
Mike
  • 9,692
  • 6
  • 44
  • 61
5
votes
6 answers

Is conditional compilation a valid mock/stub strategy for unit testing?

In a recent question on stubbing, many answers suggested C# interfaces or delegates for implementing stubs, but one answer suggested using conditional compilation, retaining static binding in the production code. This answer was modded -2 at the…
Aaron
  • 3,454
  • 23
  • 26
5
votes
2 answers

Jest: Standard way to stub named exports of ESM modules

This question is not specific to Jest as it applies to all testing libraries with stubbing capabilities. ESM modules have immutable named and default exports, which means this is no longer valid: // @filename foo.mjs export function foo() { ...…
ldiqual
  • 15,015
  • 6
  • 52
  • 90
5
votes
1 answer

Rhino Mocks: Stub & Mocks. What is the difference

I'm using Rhino Mocks in my unit test. I would like to know the difference between STUBS and MOCKS (mocks.Stub() and mocks.StrictMock()).
Yuriy
  • 51
  • 2
5
votes
1 answer

How to use Cypress to stub useSession and getSession in Next.js with next-auth

I'm trying to stub with Cypress both the frontend and backend calls to useSession() and getSession() respectively. The stubbed functions don't seem to replace the functions or get called: I'm trying to do it this way: const client =…
Trufa
  • 39,971
  • 43
  • 126
  • 190
5
votes
1 answer

What is the use of QName and Operator class?

Can anyone explain what is the use of QName, Operation and Stub class in J2ME by giving simple and understandable examples?
Amit
  • 13,134
  • 17
  • 77
  • 148
5
votes
1 answer

Stubbing HTTP requests with Mockingjay not working

I am trying to understand how to write UI tests, but I can't seem to get HTTP stubbing to work. When I run the test, I don't see the data from the stub, but the data from the API. I have tried it in Xcode 10.2 and 9.4.1, so it's not because it no…
vrwim
  • 13,020
  • 13
  • 63
  • 118
5
votes
1 answer

Stub DynamoDB in NodeJS for API

I have a problem to stub a call to DynamoDB for API testing. I'm using serverless mocha and want to test my API from an end-to-end perspective. The project structure is not straightforward, but inside the API file itself, I have a separate call to…
levo4ka
  • 2,248
  • 1
  • 19
  • 32
5
votes
6 answers

SQL server stub for java

I have a java application that is using MSSQL server through the JDBC driver. Is there some kind of stub that I can use for testing? For example I want to test how my application handle cases of connection errors, SQL server out of disk, and other…
duduamar
  • 3,816
  • 7
  • 35
  • 54
5
votes
1 answer

gRPC: creating Blocking or Future Stubs

Lately, I 'm studying to build the gRPC client-server interaction. I wrote a gRPC service : service SearchService { rpc Find (SearchReq) returns (SearchRes); } and then I should invoke it on the client side using stub(another…
lazarevsky
  • 83
  • 1
  • 7
5
votes
7 answers

TDD: Stub, Mock, or None of the Above

I'm trying to learn TDD by applying it to a simple project of mine. Some details (and an earlier question) are here: TDD: Help with writing Testable Class The specifics are I have a PurchaseOrderCollection class that has a private List of…
anonymous
  • 6,825
  • 8
  • 47
  • 60
5
votes
1 answer

Why isn't my mock getting used in my minitest test run?

I'm trying to write a test with Rails 5 and using minitest Here is my test code ... @client = Coinbase::Wallet::Client.new(api_key: ENV['COINBASE_KEY'], api_secret: ENV['COINBASE_SECRET']) sell_price = 4000 assert sell_price > last_buy_price * (1…
Dave
  • 15,639
  • 133
  • 442
  • 830
5
votes
3 answers

Stub the behavior of a readOnly property

public interface ICell { int Value{get;} void IncrementValue(); } I want to create a stub for this interface in RhinoMocks. I have a read only property and i want to increment his value every time i call the…
5
votes
1 answer

IntelliJ warning on Spock interactions when combining Mocking and Stubbing

IntelliJ IDEA (2017.2) emits the following warning on Spock interactions that combine cardinality with a return value. 'multiply' in 'org.codehaus.groovy.runtime.DefaultGroovyMethods' cannot be applied to... ...followed by the return type of the…
jaco0646
  • 15,303
  • 7
  • 59
  • 83
5
votes
0 answers

WebParam.Mode.OUT meaning and documentation

I usually create stub to interrogate external web service, It is the first time that after I created the stub of a project, in the Service.class I have this code: public void getInformation( @WebParam(name = "username", targetNamespace =…
Liz Lamperouge
  • 681
  • 14
  • 38