Questions tagged [stubs]

A stub is a small piece of code that takes the place of another component during testing.

A stub is a small piece of code that takes the place of another component during testing. The benefit of using a stub is that it returns consistent results, making the test easier to write. And you can run tests even if the other components are not working yet.

89 questions
2
votes
2 answers

How to mock a service object? should I mock it?

I have a service object called ResetPassword that handles all the logic for the ResetPassword Controller create action. I also have already tested the service object. Should I mock the service object? I figure I should since it's ready tested and it…
user2170878
  • 163
  • 1
  • 9
2
votes
2 answers

PHPUnit and Mock Objects not working

I am not sure if I am doing something wrong or it is a bug with PHPUnit and mock objects. Basically I am trying to test if $Model->doSomething() is called when $Model->start() is triggered. I am using Ubuntu in a VirtualBox, and phpunit 1.1.1…
James
  • 23
  • 1
  • 3
2
votes
1 answer

Rails - How to stub a method for the whole test suite?

Right now I'm in the middle of a refactoring and I'm struggling with the following. I have a class like this: class Example def self.some_method if Rails.env.test? true else hit_external_service end end end Now, I think…
1
vote
1 answer

About use Stubs - Java

I'm readin http://xunitpatterns.com/Test%20Stub.html and have some questions about the use of stubs, for example, in the code shown on the page the author creates a class called TimeProviderTestStub.java for use in test code. I have some doubts…
Édipo Féderle
  • 4,169
  • 5
  • 31
  • 35
1
vote
1 answer

Unit test with promise handling - node.js

i want to do a unit test with async function on the code. and here is my code on user.test.js 'use strict' const UserDomain = require("../../../../../../bin/modules/users/repositories/commands/domain") const UserHandler =…
Adithya Visnu
  • 63
  • 1
  • 5
1
vote
0 answers

Stub Promise.all using sinon

I have several promises that I am trying to resolve using Promise.all asynchronously as below: model1.find({ _id: params.id }).limit(1). lean().then((data) => { let promises = []; let p1 = model2.find({ _id: '123'…
Brijesh Prasad
  • 569
  • 6
  • 25
1
vote
1 answer

WebStorm JS Libraries TypeScript Community Stubs not showing list

I might be missing something obvious but I can't figure out what. I recently installed WebStorm on my new computer and had no problem downloading TypeScript Community Stubs libraries like Angular, Mongoose etc. from the settings (I downloaded about…
Julz
  • 157
  • 1
  • 3
  • 9
1
vote
0 answers

spyOn(obj, "method").and.passValues(first,second..) Jasmine

I'm making a ten pin bowling game and to test the bonus points feature I would like to pass in a list of hard coded outcomes (pinsHit) for each roll. Main constructor functions are Game, Frame and Roll. Since bonuses are awarded by doubling the…
Tam Borine
  • 1,474
  • 2
  • 13
  • 21
1
vote
2 answers

Where to put stub classes in Maven projects

I have a Maven project with the following directory layout: . └── src ├── main │ └── ... └── test └── java └── com.foo ├── stubs │ └──…
Michael Lihs
  • 7,460
  • 17
  • 52
  • 85
1
vote
2 answers

Oauth Model Concern Test Coverage Stubs

I am trying to figure out the best way to reach 100% test coverage on this class. I have outlined my full spec and I am hoping someone can point me in the right direction. My assumption is stubbing the Oauth2 request would do this, but I can not…
Chris Hough
  • 3,389
  • 3
  • 41
  • 80
1
vote
0 answers

Substituting a variable in a test (using mock? or otherwise) in Python

I have a function that puts some sql into a dataframe. For it I am using pandas such that my code looks like this: def get_all_sql_data(connection): code = 'select * from table1' data = pd.read_sql(code, connection) ... ... ... …
Michael Tamillow
  • 415
  • 4
  • 11
1
vote
0 answers

Testing stack exchange redis method using stubs

I have a method like below. public async Task AddAsync(IList> items) where T : class { RedisKey[] redisKeys = new RedisKey[items.Count]; RedisValue[] redisValues = new…
DevMJ
  • 331
  • 1
  • 5
  • 17
1
vote
1 answer

stub_image showing on universal image loader in recyclerview

I have implement universal image loader for showing images in recyclerview. it showing stub_image. Code contain One fragment and its adapter, its working properly before i added universal-image-loader. Here is the code: Fragment.Class public class…
1
vote
0 answers

How to invoke post method using stubs and mocks in ruby on rails

Im new to this mocking and stubbing in rspec. Actually in my controller, i have an action method invite. I would like to mock/stub this invite method in my contoller.... Below is my code: when(/^I invite a subject with required attributes$/) do …
Sheharose
  • 295
  • 3
  • 14
1
vote
1 answer

Grunt-stubby and protractor task

I use Grunt in my project with angular and node. For the tests i use cucumber + protractor + grunt-stubby here is my register task from Gruntfile.js grunt.registerTask('test', [ 'selenium_start', 'clean:server', …
Toni Chaz
  • 651
  • 11
  • 22