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

Do I Stub or Shim a method inside my test method?

I have a method base.ResolveDate() inside my test method that's coming from a base class and its public and virtual. I want to stub/shim this method with my own, so do I stub or shim? Stub or Shim, how would I go about doing it? From my experience…
chuckd
  • 13,460
  • 29
  • 152
  • 331
4
votes
1 answer

rspec view stubs and partials

I'm testing a view with RSpec (2.12 on Rails 3.2.8). I'm using CanCan to conditionally display certain elements on a page. This requires a controller method 'current_user'. In some of my specs I've been able to stub out current_user, eg. …
John Small
  • 942
  • 2
  • 12
  • 21
3
votes
3 answers

How to create JAXWS web service server skeletons from wsdl ( not in IDE)

i can't find any where how to create web service from server skeletons ( java pojo's )from wsdl using JAXWS. The only tutorials I see are using automated wizard in NetBeans and and axis2 in eclipse. Can someone please give me hints on how to…
user63898
  • 29,839
  • 85
  • 272
  • 514
3
votes
1 answer

How to practically use Stub or Mocking objects in iOS testing?

My question has two parts. First I know very basic of testing in iOS and I am trying to learn when we using mocking. As far as I know mocking object is a simulation of fake objects when it is difficult to access that object such as querying a…
Bernard
  • 4,240
  • 18
  • 55
  • 88
3
votes
2 answers

autotools: don't include library when doing “make check”

So I'm writing tests for my code, and I want to stub out the calls to library functions (make sure that it's calling the right library calls at the right time, and that it handles errors appropriately). I think I'm SOL with the C standard library…
rampion
  • 87,131
  • 49
  • 199
  • 315
3
votes
3 answers

Cannot throw an exception using Mockito

When the method is running I would like to throw an exception (while testing). I could do few things: stub(mock.someMethod("some arg")).toThrow(new RuntimeException()); when(mock.someMethod("some arg")).thenThrow(new…
sergey136
  • 63
  • 1
  • 7
3
votes
2 answers

Where to load stub data from when unit testing

For purposes of unit testing, I need to mock up a network response. The response is normally a byte stream, stored as a const vector. For the unit test however, I would like to produce the vector with data that is either hardcoded in the…
Justin R.
  • 23,435
  • 23
  • 108
  • 157
3
votes
1 answer

Microsoft Fakes (Shims and / or Stubs) on a c# method with SQL code

I am trying to learn a bit more about Unit Testing, using out-of-the-box functionality (i believe it is MSTest.exe), and Microsoft Fakes (stubs and Shims). I am using Visual Studio 2012 Ultimate and .Net 4.5 Framework. Given the following code that…
Kyle
  • 951
  • 3
  • 14
  • 31
2
votes
0 answers

example for mocks and stubs in cxxtest

I am using cxx test for unit testing. I have the proper setup for everything and I have written test cases for some simple functions but with a lot of dependencies in the code, I am finding it difficult to write more test suites. I have searched…
Alok Kumar
  • 21
  • 1
2
votes
0 answers

jasmine test cases dependency in angular 2 with stub

Here I'm new to angular 2 test cases with jasmine + karma and I'm following this testing guide I tried to write test case but unable to write correctly and getting routing error as test cases are going to server while running, although it should…
Nimish
  • 1,053
  • 13
  • 29
2
votes
1 answer

Sinon - basic use with internal functions

I'm having trouble getting the basics of testing my code using sinon. I have a simple module that calls two internal functions and checks their result. I was to use a stub to vary the output of these functions to test how the module responds. Is…
Steve
  • 21
  • 3
2
votes
1 answer

Test failing - one class method to call another ("expected: 1 time with arguments, received 0 times")

My problem: I'm trying to stub a class method that returns an instance of that class, but I'm getting the following error for the test entitled "creates an instance with CSV data": Failures: 1) QuestionData.load_questions creates an instance…
2
votes
1 answer

Difference between a stub, a mockito "mock" class, and a Robolectric "shadow" object

These are obviously related and have some similarities, but I am not sure what sets them apart. In the robolectric documentation, it is emphasized that Shadow Classes are not Mock or Stub classes. How are these different, and how would each be used?…
farid99
  • 712
  • 2
  • 7
  • 25
2
votes
1 answer

issue with stubs and rspec old syntax

I am writing some code and using rspec but received a warning that the syntax is old and i can't quite figure out how i should be writing it instead? it "should calculate the value correctly" do mock_cards = [Card.new(:clubs, 5),…
Lilp
  • 961
  • 1
  • 11
  • 31
2
votes
2 answers

How to stub a instance method for a specific instance?

I have below case, class Schools::Status def initialize(school) @school = school end def active? true end end Now, I want to stub active? method for a specific school. One way to have like this…
Sandip Ransing
  • 7,583
  • 4
  • 37
  • 48