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

Amazon S3 standalone stub server

I seem to recall reading about an Amazon S3-compatible test server that you could run on your own server for unit tests or whatever. However, I've just exhausted my patience looking for this with both Google and AWS. Does such a thing exist? If not,…
Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285
19
votes
2 answers

Sinon not stubbing property value of object

I am using sinon v4.1.2. According to the documentation (http://sinonjs.org/releases/v4.1.2/sandbox/), I should be able to set a property using the following: sandbox.stub(myObject, 'hello').value('Sinon'); However, I am getting the…
Westy
  • 707
  • 2
  • 10
  • 23
18
votes
2 answers

Please explain how to create PHP's Phar stubs

I'm trying to create a very simple PHP CLI application that can be run as a phar file from the command line: # php myProject.phar This is what I've tried so far: My Project My project is in a directory called MyProject and it has these two files in…
JW.
  • 4,821
  • 5
  • 43
  • 60
18
votes
5 answers

Rspec: Stub method that is in the controller

May I know how to stub method that is in the controller create method? I need to write the spec for this but I got these errors. I need to check the create method in controller must execute validate_fbid method before create a new company record in…
shoujo_sm
  • 3,173
  • 4
  • 37
  • 60
17
votes
5 answers

Mocking a method that returns a sealed class in RhinoMocks

Running this code: _foo = MockRepository.GenerateStub(); _foo.Stub(x => x.Foo()).Return("sdf"); When public interface IBar { string Foo(); } public class Bar : IBar { public string Foo() { throw new NotImplementedException(); …
ripper234
  • 222,824
  • 274
  • 634
  • 905
17
votes
2 answers

What are "stubbed child components" in Vue Test Utils?

Vue Test Utils has an API method called shallowMount() that: ...creates a Wrapper that contains the mounted and rendered Vue component, but with stubbed child components. I've searched the Vue Test Utils documentation website but failed to find a…
urig
  • 16,016
  • 26
  • 115
  • 184
17
votes
4 answers

what is a stub routine?

In regards to C what is a stub routine? Also an example would be much appreciated as well.
Dustin Gamester
  • 792
  • 3
  • 8
  • 24
17
votes
3 answers

How to test background jobs (Sidekiq) with Rspec?

A large part of my application relies on background jobs to process user's websites, so I need to write some tests to cover these. First question is how to test code that's in a Sidekiq worker class, for example app/workers/some_worker.rb class…
mind.blank
  • 4,820
  • 3
  • 22
  • 49
17
votes
1 answer

Android unit testing with Junit: testing network/bluetooth resources

I am slowly becoming obsessed with unit testing. I am trying to develop as much software as I can using test-driven development. I am using JUnit to unit test my android applications. I have been working on an app that uses bluetooth and am having a…
aleph_null
  • 5,766
  • 2
  • 24
  • 39
16
votes
1 answer

Unit testing - stubbing an SqlDataReader

We have an n-tier web application that pulls data from SQL Server. Our Data Access logic returns an SqlDataReader whose data is then used to create our Business objects (a.k.a. Data Transfer objects). We wish to build unit tests to check our code…
DrGriff
  • 4,394
  • 9
  • 43
  • 92
16
votes
4 answers

C++ Unit Testing: Stubs (not mocks)?

Just getting into Unit Testing with C++. It looks like I will need to write several stub classes as I go along. My understanding is there is a difference between Mocks and Stubs. Basically it seems Mocks are for when you are testing something…
User
  • 62,498
  • 72
  • 186
  • 247
16
votes
1 answer

Should I share gRPC Stubs or Channels?

The gRPC C++ API for creating channels returns a shared_ptr. The generated function NewStub returns a unique_ptr. However I've seen reports of people having issues trying to create multiple instances of a stub type, sharing a channel. Their solution…
Ken
  • 693
  • 1
  • 7
  • 15
16
votes
3 answers

Is there any simulator/tool to generate messages for streaming?

For testing purpose, I need to simulate client for generating 100,000 messages per second and send them to kafka topic. Is there any tool or way that can help me generate these random messages?
Sameeksha Raina
  • 199
  • 1
  • 2
  • 9
16
votes
2 answers

What is the difference between rhino-mocks stub and expect

What is the difference between rhino-mocks stub and expect here: Looks to me that they behave exact the same? mockContext.Stub(x => x.Find()) .Return(new List() { new Blog() { Id = 1, Title = "Test" } …
Nikos
  • 7,295
  • 7
  • 52
  • 88
15
votes
2 answers

How do I stub an event emitter with Sinon.js

I am trying to stub the following: on('complete', function(data){ }); I only want to call the callback if the first parameter is 'complete'. The function I am testing also contains: on('error', function(data){ }); So I can't just do yield cause…
Pickels
  • 33,902
  • 26
  • 118
  • 178
1 2
3
73 74