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
7
votes
0 answers

Stubbing Swift Extension for Unit testing

I am looking into unit-testing a Swift class which uses Alamofire network library. What I want to do is to stub the download function of the library's Manager class with some simple behaviours that does not use the filesystem so that I can isolate…
7
votes
2 answers

Stub/mock process.platform sinon

I am working with process.platform and want to stub that string value to fake different OSes. (this object is generated out of my reach, and I need to test against different values it can take on) Is it possible to stub/fake this value? I have…
Automatico
  • 12,420
  • 9
  • 82
  • 110
7
votes
4 answers

Which is the best isolation framework for Java? JMock, Easymock, Mockito, or other?

I realize this has been asked before, but the last time was in mid 2008. If you were starting a new project right now, which one would you use and why? What are their strengths/weaknesses regarding readability, usability, maintainability, and…
Dave
  • 21,524
  • 28
  • 141
  • 221
7
votes
1 answer

Cucumber/Capybara - The use of doubles or partial doubles from rspec-mocks outside of the per-test lifecycle is not supported

I know that we generally don't want to stub a method in acceptance/feature tests, but this is something I ABSOLUTELY need to stub for all of my acceptance/feature tests. When I put the stub call in Before block in env.rb or in a Background step, I…
yangtheman
  • 509
  • 4
  • 21
7
votes
5 answers

Build a Visual Studio Project without access to referenced dlls

I have a project which has a set of binary dependencies (assembly dlls for which I do no have the source code). At runtime those dependencies are required pre-installed on the machine and at compile time they are required in the source tree, e,g in…
David Reis
  • 12,701
  • 7
  • 36
  • 42
7
votes
2 answers

How to mock objects in Erlang using Meck?

Okay, I'm using Meck and I'm lost. My first language (that I've been writing for about 7 months) is Ruby, so I can't seem to wrap my brain around Meck mocking yet. I do get Ruby mocking though. Hoping someone can help me. Also, I've only been…
Kelly
  • 619
  • 8
  • 18
6
votes
4 answers

Why there is a stub for MS-DOS in PE files?

In recent versions of PE files there is a stub to show for MS DOS users the sentence This program can not be run in DOS mode. Why such message still exists althogh it wastes about 38 bytes? Is there any one still uses MS-DOS?
Aan
  • 12,247
  • 36
  • 89
  • 150
6
votes
2 answers

RhinoMock : How to Stub and Return a method with complex object as parameter

I highly appreciate anyone can help me in below-mentioned issue: I've been using RhinoMock in Unit Test. I define my mock object in such manner, with sessionToken is string-typed: mockRepository.Stub(repository =>…
Undefined Identity
  • 475
  • 3
  • 7
  • 16
6
votes
1 answer

Stub a controller helper method in a template helper spec

My ApplicationController exposes a method (e.g. sort_direction) to the view templates by using helper_method :sort_direction. I then use this method in another method (e.g. sort_link) of a view helper (application_helper.rb). When testing the…
medihack
  • 16,045
  • 21
  • 90
  • 134
6
votes
1 answer

rspec: Stub a template's helper method call from a controller spec using render_views

From Rails 3 / Rspec 2, I'm attempting to leverage the render_views feature of controller specs. The issue I've come across is that we've just installed the kaminari pager gem, and I want to stub out the <%= paginate @sites %> call from my view so…
Gabe Martin-Dempesy
  • 7,687
  • 4
  • 33
  • 24
6
votes
2 answers

UnitTestIsolationException : Failed to resolve profiler path from COR_PROFILER_PATH and COR_PROFILER environment variables

I am using VS2015 with Update 3. I have a simple hello world unit test project where I am trying to get the shimContext , below is the code snippet. I am getting the exception at shimContext to create call:…
Somu
  • 515
  • 1
  • 5
  • 12
6
votes
1 answer

Can I add custom side-effects to a stub in Rails Mocha?

My team uses the Mocha gem for stubbing in Rails. I understand how to stub a method with stubs such that it does nothing, or returns a specific value, but is there a way to stub it such that it runs a certain line of code when called? I'm looking…
6
votes
1 answer

Difference Stub Fixture

I am learning codeception and I wonder what is the difference between stubs and fixtures. Both help me to load well-defined data and kepp tessts simple. But when do I use \Codeception\Util\Stub and when do I use \Codeception\Util\Fixtures
astridx
  • 6,581
  • 4
  • 17
  • 35
6
votes
1 answer

Mock fs.readdir for testing

I'm trying to mock the function fs.readdir for my tests. At first I've tried to use sinon because this is a very good framework for this, but is hasn't worked. stub(fs, 'readdir').yieldsTo('callback', { error: null, files: ['index.md', 'page1.md',…
Jan Baer
  • 1,105
  • 1
  • 12
  • 15
6
votes
3 answers

How do I stub a method of an instance only if a specific instance variable has a value?

I have an object MyObject: class MyObject def initialize(options = {}) @stat_to_load = options[:stat_to_load] || 'test' end def results [] end end I want to stub the results method only if stat_to_load = "times". How can I do…
Sebastien
  • 6,640
  • 14
  • 57
  • 105