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
4
votes
1 answer

How to generate JavaScript client stub from WADL?

I want to generate a JavaScript stub for invoking the RESTful web service defined in this wadl: http://idi.fundacionctic.org/mobSerenoaWS/application.wadl I tried with the NetBeans REST Web Service plugin on NetBeans 7.0.1. I downloaded the Wadl…
Federico Bellucci
  • 623
  • 2
  • 7
  • 26
4
votes
2 answers

Shortcut to create a javascript function stub in Sublime Text 2

Is it possible to quickly create a method stub in Sublime Text 2? Perhaps a package I could install? For example, I bind something in jquery - $("p").bind("click", {foo: "bar"}, handler) Could I rightclick on handler, then choose an option to stub…
Finnnn
  • 3,530
  • 6
  • 46
  • 69
4
votes
2 answers

RSpec Stubbing: return in a sequence

I know the following things work: returning a parameter subject.should_receive(:get_user_choice){ |choices| choices.to_a[0] } and a sequence (it will return a 0 on the first call, and the second time…
Len
  • 2,093
  • 4
  • 34
  • 51
4
votes
1 answer

How do I stub a class in a module in Python for testing?

I have a module I am using which uses RealClass, so it is an internal dependency I don't have access to. I want to be able to create a FakeClass which replaces the functionality of the RealClass for testing. I don't want to replace individual…
dre
  • 1,422
  • 3
  • 21
  • 31
4
votes
4 answers

How to stub a static method?

I am working on a brownfield application and am currently refactoring part of it. I am trying to do this in a TDD fashion but am running into a problem. Part of the code I am testing does var siteLanguages = from sl in…
olle
  • 4,597
  • 24
  • 28
4
votes
2 answers

Cypress testing of redirects to different origins (cross-origin)

My web application, on load, automatically redirects the user to a URL on a different origin via the window.location.replace method based on their user parameters. When Cypress tests my application and attempts to follow the redirect, it detects the…
MattSidor
  • 2,599
  • 4
  • 21
  • 32
4
votes
1 answer

Mockito 3 any() Strict stubbing argument mismatch

I'm using Mockito 3.1.0. I'm trying to Mock my method with this syntax: when(mockedObject.myMethod(any(HttpServletRequest.class)).thenReturn(1); myMethod is simply: public Integer myMethod(HttpServletRequest request) { return 0; } In the…
Izaya
  • 1,270
  • 2
  • 13
  • 31
4
votes
4 answers

Mocking superclass method call using mockito is not working

I have been trying to stub the superclass method call from the subclass overridden method, but till now I am stuck without any luck to succeed. I have extensively searched on the google and SO questions as well. Here is the test code that I am…
theimpatientcoder
  • 1,184
  • 3
  • 19
  • 32
4
votes
2 answers

Android Local Service Sample, bindservice(), and ServiceConnection()

I have a question which is related to this question that was asked by @mnish about a year ago. Please have a look at his question and code. He implements a ServiceConnection() and passes it to bindService(). This follows the Local Service Sample in…
Marie
  • 691
  • 4
  • 12
  • 23
4
votes
1 answer

Sails.js: Unable to stub a helper for unit testing purposes

Node version: v12.18.3 Sails version (sails): 1.2.3 I am unable to stub a sails helper when performing unit tests. I have a helper that handles all the communication with a database. Moreover, I have an API, which uses this helper. In my tests, I…
Nicolas El Khoury
  • 5,867
  • 4
  • 18
  • 28
4
votes
0 answers

Invalid prop for child component, despite using shallowMount

I am testing a Vue component that includes a child component. That child components takes 2 props. In my snapshot test for the parent component, I shallowMount it (so the child component shouldn't render). However, I keep getting a warning saying:…
tx291
  • 1,251
  • 6
  • 24
  • 42
4
votes
1 answer

Boto Stubber SQS

I need to mock Boto SQS receive messages, but I receive an error: AttributeError: 'Stubber' object has no attribute 'receive_message' The sqs_client property is a Stubber but receive_message is not recognized, and I don't know why. import…
JoeLoco
  • 2,116
  • 4
  • 31
  • 59
4
votes
1 answer

Stub controller action in Rspec controller test, but it's still executed

I would like to test if a controller action is actually called without a redirect happening in some before_filter. Since the controller action itself may do a redirect, I want to stub the action to raise a specific error (SuccessfulActionError or…
Manuel Meurer
  • 3,238
  • 6
  • 35
  • 50
4
votes
3 answers

How to stub document method with sinon - React

import React, { PropTypes, Component } from 'react'; import classNames from 'classnames/bind'; import { get, includes } from 'lodash'; import { Link } from 'react-router'; import * as styles from '../CAMNavPanel.css'; const cx =…
vini
  • 4,657
  • 24
  • 82
  • 170
4
votes
1 answer

What is proxy and stub in web-services?

As per definition from https://channel9.msdn.com/Forums/TechOff/203516-Whats-a-proxy-stub Proxy is the piece of code that doesn't perform any functions of its own, but instead is responsible for calling the real code. But I am not clear about…
Roshan
  • 873
  • 12
  • 33