Questions tagged [stub]
The stub tag has no summary.
17 questions
5 votes
3 answers
2k views
Should I make my class mockable by marking its methods as virtual or by creating an interface?
In the process of refactoring non-testable code we are re-designing some of ours classes so that it can be easily replaced by a stub or mock during unit tests. Here is an example of such class (...
0 votes
3 answers
2k views
Unit Testing: Constructor Injection with Fake Objects - Bad Tests?
In The Art of Unit Testing, 2nd Ed., the author gives the following example for injecting a stub using constructor injection and a "fake object". The goal of the "fake object" is to inherit the ...
125 votes
9 answers
54k views
How exactly should unit tests be written without mocking extensively?
As I understand, the point of unit tests is to test units of code in isolation. This means, that: They should not break by any unrelated code change elsewhere in the codebase. Only one unit test ...
0 votes
1 answer
318 views
When to use stubs
I'm trying to get into TDD, and a lot of examples sugests that we should use stubs to make our code more flexible. If I'm using javascript (for example) then why should I use stubs, since methods and ...
14 votes
4 answers
2k views
Do mocks violate the Open/Closed principle?
Some time ago I read, on a Stack Overflow answer that I can't find, a sentence that explained that you should test public APIs, and the author said that you should test interfaces. The author also ...
0 votes
2 answers
950 views
Best practice to return a long string in a stub
I have some methods im trying to test which use a StreamReader dependency that i mock using Rhino mocks. But it is a large xmlFile. In the spirit of unit testing im trying to keep away from using a ...
0 votes
2 answers
316 views
Correct Seam for Stub
In Chapter 3 of his book The Art of Unit Testing: with Examples in C#, Roy Osherove illustrates the issue of undesirable external dependencies in code under test. He shows this with a method named ...
0 votes
4 answers
4k views
Moving from mock to real objects?
I'm like doing TDD so I started everything mocking objects, creating interface, stubbing, great. The design seems to work, now I'll implement the stuff, a lot of the code used in the stubs are going ...