Questions tagged [stubbing]

Stubbing is modifying an instance method or property of an object at runtime to extend its functionality.

420 questions
8
votes
1 answer

Rspec double expect/allow anything

I have a test double that I'd like to be able to receive any message. I know I can expect the double to receive a certain message and return a value like so: foo = double() allow(foo).to receive(:bar) { "Foobar" } I can also allow foo to receive…
jordelver
  • 8,292
  • 2
  • 32
  • 40
8
votes
1 answer

Populating instance variables in rspec tests

I have a class which has the following initialise method. def initialize(my_var) @my_var = my_var end and I want to test the method which then does something to @my_var def split @my_var.split(",") end how do I change @my_var before testing…
Joseph Le Brech
  • 6,541
  • 11
  • 49
  • 84
7
votes
1 answer

How to use the real parameters when creating a stub method in RhinoMocks?

I want to create a stub of the following interface: interface IUnitOfWork { void DoInTransaction(Action method); } In the stub object, all I want DoInTransaction to do is run method(). Something like: // pseudo-code unitOfWorkStub.Stub(x =>…
Ilya Kogan
  • 21,995
  • 15
  • 85
  • 141
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

Python mockito - Mocking a class which is being instantiated from the testable function

I am bit lost while writing the test case for UserCompanyRateLimitValidation class. I am finding difficulty in mocking the class which is being instantiated from inside this class. class UserCompanyRateLimitValidation: def __init__(self,…
Bhupesh Pant
  • 4,053
  • 5
  • 45
  • 70
7
votes
1 answer

Given wsdl + xds type file, how do I create a stub WCF webservice?

I understand this is a basic topic but never done this before starting from wsdl. I am being handed a wsdl file and a bunch of xsd with the types definitions. I don't have a clue if they were created from a WCF service (I guess so because of the…
JohnIdol
  • 48,899
  • 61
  • 158
  • 242
7
votes
3 answers

How can I stub the Properties.Settings object when the unit test is in a different assembly?

I have an object the references a bunch of Properties.Settings.Default... values and I need to stub these in the unit test for this object. Unfortunately the type for the settings object is declared as internal and so I can't access it from the unit…
Glenn Slaven
  • 33,720
  • 26
  • 113
  • 165
6
votes
1 answer

Rails Rspec allow_any_instance_of raises "does not implement" error for ActiveRecord object attributes

I have next problem. When I try to stub instance method of ActiveRecord model with allow_any_instance_of I receive error message "Model does not implement #method", BUT if i send real request to database for create or select instance object of this…
eugene_trebin
  • 1,485
  • 1
  • 16
  • 29
6
votes
3 answers

Mockito doesn't correctly stub methods taking list as argument

I am trying to mock a class and return a stubbed list of objects when a method on the mocked object is called. Lets consider following code : interface MyRepositry{ public List getMyClassInstances(String str,Long id,List
Shailesh Vaishampayan
  • 1,766
  • 5
  • 24
  • 52
6
votes
1 answer

Stubbing/mocking intent in Android Espresso test

I want to test the following flow in my application: The user clicks on a scan button onClick a ZXing app is launched If a correct qr code is returned we proceed else user gets an option to enter the code manually I want to test this flow using…
Ubaier Bhat
  • 854
  • 13
  • 33
6
votes
1 answer

Mockito vs JMock

I am experimenting with converting some of my unit tests from using JMock to using Mockito and have hit a few stumbling blocks. Firstly in my tests when using JMock the verification and returning of the stub happen in one step as follows …
Clinton Bosch
  • 2,497
  • 4
  • 32
  • 46
6
votes
2 answers

Stubbing ActiveRecord associations

Say I have a Company which may contain many employees of type Employee may contain many tasks of type Task. class Company < ActiveRecord::Base; has_many :employees; end class Employee < ActiveRecord::Base; belongs_to :company, has_many :tasks;…
carpamon
  • 6,515
  • 3
  • 38
  • 51
6
votes
3 answers

Stubbing when an object's constructor builds another object

So I've got some code that, grossly simplified, looks like this: class B def initialize opts @opts = opts end end class A def initialize opts # defaults etc applied to opts @b = B.new opts end end In other words, when I…
lambshaanxy
  • 22,552
  • 10
  • 68
  • 92
5
votes
2 answers

Writing Synthetic/Bridge method in java

I am writing an application which checks if the method is sythentic or bridge. For testing this application I have added various methods in my stub. But for none of the method this block is getting covered in the test case. Stub contains methods…
java_enthu
  • 2,279
  • 7
  • 44
  • 74
5
votes
2 answers

Wiremock :How to read the stub from a file in wiremock?

Currently I am setting up request and response in my stub through my java code like below. wireMockRule.stubFor(WireMock.get(WireMock.urlEqualTo("/abc/xyz")) .willReturn(WireMock.aResponse() .withBody("Hey") …