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

Stubbing WebSocket in JavaScript with Jasmine

I try to test if onmessage is a proper function. Here is a test: describe(".init(address, window)", function() { beforeEach(function() { address = 'ws://test.address'; window = {}; e = { data: {} } …
ciembor
  • 7,189
  • 13
  • 59
  • 100
8
votes
1 answer

Using Spock to stub both Gorm and other methods in a Grails domain class

Sorry if this is a newbie question but I would really appreciate any insights the community could offer with regard to a problem I am having with stubbing the following method which I have in a Grails service, LocationService. Location locate(String…
Paddy
  • 83
  • 1
  • 3
8
votes
7 answers

How do I include test classes and configuration in my war for integration testing using maven?

I currently have a maven web project that I am attempting to write integration tests for. For the structure of the project, I've defined test stubs under src/test/java, whilst the spring bean definitions for these stubs sit under…
Peter Nguyen
  • 173
  • 2
  • 5
8
votes
4 answers

Stubs / Mocks vs. Service Virtualization..? Yikes

I'm currently investigating unit testing in hard-to-reach areas (that's a very high-level view, I know) and I've come up against this question: stubs / mocks or service virtualization? I'm reading in pursuit of the answer, but the only resources I…
Tom Tom
  • 422
  • 4
  • 14
8
votes
1 answer

What is the difference in OCMock expect and stub methods?

I am trying to use OCMock for testing my app. But I am confused where should we use expect and where to use stub? Can anyone help please?
sanjana
  • 203
  • 2
  • 5
7
votes
2 answers

How to stub/mock JDBC ResultSet to work both with Java 5 and 6?

I'm testing some of my classes working with JDBC statements etc and now I got problem with JDBC ResultSet interface: The software should run both with Java 5 and Java 6 and hence the tests should also be run with both versions. Unfortunately Java 6…
Touko
  • 11,359
  • 16
  • 75
  • 105
7
votes
0 answers

Why are some dll static-linking stub libs (import libraries) so big?

I noticed while linking to the pcl (point cloud library) that some of the dll stub libs have more than 10MB where the dll themselves have less than half of that size (these are release builds!). Shouldn't the stub lib only contain minimal…
Oliver Zendel
  • 2,695
  • 34
  • 29
7
votes
2 answers

Django & mypy: ValuesQuerySet type hint

What type hint to use for a function which returns a queryset like the one below? def _get_cars_for_validation(filter_: dict) -> QuerySet: return ( Car.objects.filter(**filter_) .values("id", "brand", "engine") …
Dušan Maďar
  • 9,269
  • 5
  • 49
  • 64
7
votes
1 answer

Sinon - Stub module function and test it without dependency injection

I have a proxy module, which forwards function calls to services. I want to test if the service function is called, when a function in this proxy module is called. Here is the proxy module: const payService = require('../services/pay') const…
AFMeirelles
  • 409
  • 3
  • 8
  • 25
7
votes
1 answer

Rspec newbie: Quick example of nested controller test?

I'm just starting out with RSpec and having a little difficulty writing up controller tests for nested resources. I've tried googling this, but without much luck. Could someone offer a basic example of a "PUT update" test test ensures a nested…
PlankTon
  • 12,443
  • 16
  • 84
  • 153
7
votes
1 answer

MeteorJS: How to stub validated method in unit test

I am using validated methods (mdg:validated-method) with LoggedInMixin (tunifight:loggedin-mixin). Now I have a problem with my unit tests, as they fail with notLogged error, because in the unit tests there is no logged user of course. How do I have…
user3142695
  • 15,844
  • 47
  • 176
  • 332
7
votes
4 answers

How to parse the output received by gRPC stub client from tensorflow serving server?

I have exported a DNNClassifier model and run it on tensorflow-serving server using docker. After that I have written a python client to interact with that tensorflow-serving for new prediction. I have written the following code to get the response…
user3457384
  • 593
  • 6
  • 14
7
votes
1 answer

How Sinon stubs works under the hood?

In the last months I've been working with JavaScript and using SinonJS to stub some behaviours. I've manage to make it work, I've stubbed lots of methods and everything works great. But I still have some questions about how Sinon works under the…
Lucas Beier
  • 621
  • 1
  • 7
  • 19
7
votes
4 answers

Sinon.js, only stub a method once?

I am wondering is there is a possibility in sinon.js to stub a method only once? For example: sinon.stub(module, 'randomFunction', 'returnValue/function'); In my test this module.randomFunction will be called multiple times in the same test, but I…
jruts
  • 396
  • 4
  • 11
7
votes
1 answer

Create an EF entity stub with AutoFixture

For example I've got these partial classes that was generated by EF Database First: Dog: (EF entity) public partial class Dog { public int DogID { get; set; } public string Name { get; set; } public int Age { get; set; } public int…
AsValeO
  • 2,859
  • 3
  • 27
  • 64