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

Possible to stub method twice within a single test to return different results?

I would like to re-stub someHandler.getStatus, but I'm getting TypeError: Attempted to wrap getStatus which is already wrapped .. it('is a test', function() { sandbox.stub(someHandler, 'getStatus', function(callback) { callback(null, { …
bobbyrne01
  • 6,295
  • 19
  • 80
  • 150
37
votes
7 answers

Django unit testing with date/time-based objects

Suppose I have the following Event model: from django.db import models import datetime class Event(models.Model): date_start = models.DateField() date_end = models.DateField() def is_over(self): return datetime.date.today() >…
Fragsworth
  • 33,919
  • 27
  • 84
  • 97
36
votes
3 answers

What is " Stub " and "AIDL" for in java?

Question 1: I am studying Android service and often see code like this: private ISampleService.Stub sampleServiceIf = new ISampleService.Stub(){} What is .Stub ? Question 2: I checked "AIDL", but I want to know why we have to use that instead of…
AmyWuGo
  • 2,315
  • 4
  • 22
  • 26
33
votes
3 answers

RSpec: Stub chains with arguments?

Just wondering if/how arguments can be passed in rspec stub chains. To give an example, suppose I have the following action: def index @payments = Payment.order(:updated_at).where(:paid => true) @bad_payments =…
PlankTon
  • 12,443
  • 16
  • 84
  • 153
33
votes
3 answers

Is there a way to undo Mocha stubbing of any_instance in Test::Unit

Much like this question, I too am using Ryan Bates's nifty_scaffold. It has the desirable aspect of using Mocha's any_instance method to force an "invalid" state in model objects buried behind the controller. Unlike the question I linked to, I'm not…
Craig Walker
  • 49,871
  • 54
  • 152
  • 212
31
votes
11 answers

rspec: How to stub an instance method called by constructor?

class A def initialize @x = do_something end def do_something 42 end end How can I stub do_something in rspec, before the original implementation is called (thus assigning 42 to @x)? And without changing the implementation, of…
Pedro
  • 2,813
  • 2
  • 22
  • 16
30
votes
6 answers

EntityFunctions.TruncateTime and unit tests

I'm using System.Data.Objects.EntityFunctions.TruncateTime method to get date part of a datetime in my query: if (searchOptions.Date.HasValue) query = query.Where(c => EntityFunctions.TruncateTime(c.Date) == searchOptions.Date); This…
Jakub Konecki
  • 45,581
  • 7
  • 87
  • 126
29
votes
14 answers

What is an easy way to stub / dummy a restful web service?

I want to create an android application, this application will make RESTful calls to a web service to obtain some data. I know what the RESTful interface will be, but I don't want the hassle of creating my own implementation. Is there an easy way to…
Jimmy
  • 16,123
  • 39
  • 133
  • 213
28
votes
4 answers

RSpec: how to stub inherited method current_user (w/o Devise)?

I have a controller based on MHartl's RoR4 Tutorial And just like MHartl, I'm not using Devise, I rolled my own authentication system Having trouble with the RSpec for UsersController#Edit since the view has a call to current_user.admin? and the…
Chiperific
  • 4,428
  • 3
  • 21
  • 41
27
votes
2 answers

How to stub static methods with sinon in ES6?

var MyClassStub = sinon.createStubInstance(MyClass); MyClassStub doesn't contain static methods. How to fix that?
Rostislav Shtanko
  • 704
  • 2
  • 9
  • 30
27
votes
5 answers

Usage of Assert.Inconclusive

I'm wondering how someone should use Assert.Inconclusive(). I'm using it if my unit test would be about to fail for a reason other than what the test is for. For example, I have a method on a class that calculates the sum of an array of ints. On the…
Johannes Rudolph
  • 35,298
  • 14
  • 114
  • 172
24
votes
3 answers

PowerMock: stub methods from parent class

I'm using PowerMock and I'd like to know how to keep all behavior of the child class, but stub super calls that may be overriden by the child. Say I have this class: public class A { public String someMethod() { return "I don't want to…
jchitel
  • 2,999
  • 4
  • 36
  • 49
23
votes
2 answers

Stubbing a Property get using Rhino Mocks

Using RhinoMocks, I am trying to Stub the getter value of a property. The property is defined as part of a Interface with only getter access. However I get the error "Invalid call, the last call has been used or no call has been made (make sure that…
Santhosh
  • 6,547
  • 15
  • 56
  • 63
22
votes
2 answers

Stubbing a React component method with Sinon

I'm trying to stub a React component method for testing purpose: var Comp = React.createClass({ displayName: "Comp", plop: function() { console.log("plop"); }, render: function() { this.plop(); return React.DOM.div(null,…
NiKo
  • 11,215
  • 6
  • 46
  • 56
21
votes
3 answers

How to use stubs in JUnit and Java?

I have worked with JUnit and Mocks but I'm wondering, what are the differences between Mocks and Stubs in JUnit and how to use Stubs in JUnit, Java? And as Mocks that have EasyMock, Mockito and so on, what does Stubs uses in Java? Please give some…
Wooopsa
  • 320
  • 1
  • 6
  • 22
1
2
3
73 74