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
33
votes
4 answers

When to use Meteor.methods and utilizing stubs

Using Meteor, I'm attempting to understand when to use server-side Meteor.methods() while still retaining instant UI updates. From Andrew Scala's introductory tutorial, he claims that Meteor.methods() should be used when you want to update and…
bento
  • 4,846
  • 8
  • 41
  • 59
19
votes
2 answers

Python's StringIO doesn't do well with `with` statements

I need to stub tempfile and StringIO seemed perfect. Only that all this fails in an omission: In [1]: from StringIO import StringIO In [2]: with StringIO("foo") as f: f.read() --> AttributeError: StringIO instance has no attribute…
mike3996
  • 17,047
  • 9
  • 64
  • 80
16
votes
5 answers

What is wrong with Stubs for unit testing?

I just watched this funny YouTube Video about unit testing (it's Hitler with fake subtitles chewing out his team for not doing good unit tests--skip it if you're humor impaired) where stubs get roundly criticized. But I don't understand what wrong…
MatthewMartin
  • 32,326
  • 33
  • 105
  • 164
11
votes
5 answers

Why do we need mocking frameworks like Easymock , JMock or Mockito?

We use hand written stubs in our unit tests and I'm exploring the need for a Mock framework like EasyMock or Mockito in our project. I do not find a compelling reason for switching to Mocking frameworks from hand written stubs. Can anyone please…
Praneeth
  • 439
  • 2
  • 6
  • 11
11
votes
1 answer

Stubbing a prototype method with sinon

Let's say I have the following methods: Controller.prototype.refresh = function () { console.log('refreshing'); } Controller.prototype.delete = function (object) { var self = this; object.delete({id: object.id}, function () { …
Abraham P
  • 15,029
  • 13
  • 58
  • 126
10
votes
1 answer

stubbing a function in a proxyquired object

I want to unit-test the following simplified module: const Logger = require('logplease'); const logger = Logger.create('utils'); const tester = { one: () => { logger.log('called real one()'); tester.two(); }, two: () =>…
montrealist
  • 5,593
  • 12
  • 46
  • 68
10
votes
2 answers

Alternate of any_number_of_times method in stubs

I have upgraded my project to rails 4 but now I am getting some deprecation warnings and one of them is DEPRECATION: any_number_of_times is deprecated.. Code for which I am gettings this warning is sponsorship =…
Adnan Ali
  • 2,890
  • 5
  • 29
  • 50
10
votes
3 answers

Understanding stubs, fakes and mocks.

I have just started to read Professional Test Driven Development with C#: Developing Real World Applications with TDD I have a hard time understanding stubs, fakes and mocks. From what I understand so far, they are fake objects used for the purpose…
aleczandru
  • 5,319
  • 15
  • 62
  • 112
9
votes
2 answers

When to use a Mock v. Stub, or neither?

I've been reading up on Mocks and Stubs, their differences and uses. I'm still a bit confused, but I think I've got the jist of it. Now I'm wondering about applications. I can see the use in creating "fake" objects in testing scenarios where the…
7
votes
1 answer

How to make vs2010 auto generate method stubs at the end of file

I try to auto generate method stub using visual studio's View.ShowSmartTag functionality When I choose this option, Method8 will be placed right after Method2 but I want to place it after all methods, Method7 in this case. Is there any settings for…
Vitalii Korsakov
  • 45,737
  • 20
  • 72
  • 90
6
votes
1 answer

Unit Testing with NSURLSession for OCMock

I have a networking class called: ITunesAlbumDataDownloader @implementation AlbumDataDownloader - (void)downloadDataWithURLString:(NSString *)urlString completionHandler:(void (^)(NSArray *, NSError *))completionHandler { …
GameDev
  • 445
  • 7
  • 21
5
votes
0 answers

Is there a way to mock Parse.com response in order to use them in unit testing for iOS?

I will use Nimbleparse as backend and I'm writing tests in my iOS project using the parse-SDK-ios. Is there a way to simulate responses, for example when I try to signin a PFUser? Like using stubs for common http requests. Thank you
Oscar J. Irun
  • 455
  • 5
  • 17
4
votes
3 answers

Optional parameters with a stub in RhinoMock

I want to stub a function that receive 2 boolean parameters. The first is required and the second is optional. If I try to send Arg.Is.Anything to the first but without information for the second, I receive an error: System.InvalidOperationException…
Samuel
  • 12,073
  • 5
  • 49
  • 71
4
votes
1 answer

Mocks or Stubs?

I have a method that calls two other methods in it. def main_method(self, query): result = self.method_one(query) count = self.method_two(result) return count def method_one(self, query): #Do some stuff based on results. #This method hits…
mohi666
  • 6,842
  • 9
  • 45
  • 51
4
votes
0 answers

How to test web Service(Controllers functionality) in node.js Express, Sequelize app.Using stubs spy and mocks?

How to test web Service(Controllers functionality) in node.js Express, Sequelize app.Using stubs spy and mocks ?
1
2 3 4 5 6