Quantcast
Channel: What's the difference between a mock & stub? - Stack Overflow
Browsing all 43 articles
Browse latest View live

Answer by nitishagar for What's the difference between a mock & stub?

I like the explanation put out by Roy Osherove in his talk Understanding Mock Objects:Every class or object created is a fake. It is a mock if you assert against it. Otherwise it is a stub.

View Article


Answer by Dimos for What's the difference between a mock & stub?

Right from the paper Mock Roles, not Objects, by the developers of jMock :Stubs are dummy implementations of production code that return canned results. Mock Objects act as stubs, but also include...

View Article


Answer by Ghini Antonio for What's the difference between a mock & stub?

I think the simplest and clearer answer about this question is given from Roy Osherove in his book The art of Unit Testing (page 85)The easiest way to tell we’re dealing with a stub is to notice that...

View Article

Answer by R01010010 for What's the difference between a mock & stub?

To be very clear and practical:Stub: A class or object that implements the methods of the class/object to be faked and returns always what you want.Example in JavaScript:var Stub = { method_a:...

View Article

Answer by Paul Sweatte for What's the difference between a mock & stub?

A stub is an empty function which is used to avoid unhandled exceptions during tests:function foo(){}A mock is an artificial function which is used to avoid OS, environment or hardware dependencies...

View Article


Answer by M_ Fa for What's the difference between a mock & stub?

A Stub is an object that implements an interface of a component, but instead of returning what the component would return when called, the stub can be configured to return a value that suits the test....

View Article

Answer by radtek for What's the difference between a mock & stub?

I have used python examples in my answer to illustrate the differences.Stub - Stubbing is a software development technique used to implement methods of classes early in the development life-cycle. They...

View Article

Answer by Lev for What's the difference between a mock & stub?

Here's a description of each one followed by with real world sample.Dummy - just bogus values to satisfy the API.Example: If you're testing a method of a class which requires many mandatory parameters...

View Article


Answer by O'Rooney for What's the difference between a mock & stub?

Reading all the explanations above, let me try to condense:Stub: a dummy piece of code that lets the test run, but you don't care what happens to it. Substitutes for real working code.Mock: a dummy...

View Article


Answer by Mustafa Ekici for What's the difference between a mock & stub?

A fake is a generic term that can be used to describe either a stubor a mock object (handwritten or otherwise), because they both look like thereal object. Whether a fake is a stub or a mock depends on...

View Article

Answer by Adarsh Shah for What's the difference between a mock & stub?

See below example of mocks vs stubs using C# and Moq framework. Moq doesn't have a special keyword for Stub but you can use Mock object to create stubs too. namespace UnitTestProject2{ using...

View Article

Answer by Harry for What's the difference between a mock & stub?

Stub helps us to run test. How? It gives values which helps to run test. These values are itself not real and we created these values just to run the test. For example we create a HashMap to give us...

View Article

Answer by happygilmore for What's the difference between a mock & stub?

If you compare it to debugging:Stub is like making sure a method returns the correct valueMock is like actually stepping into the method and making sure everything inside is correct before returning...

View Article


Answer by Ryszard Dżegan for What's the difference between a mock & stub?

ForewordThere are several definitions of objects, that are not real. The general term is test double. This term encompasses: dummy, fake, stub, mock.ReferenceAccording to Martin Fowler's article:Dummy...

View Article

Answer by Elisabeth for What's the difference between a mock & stub?

Stubs are used on methods with an expected return value which you setup in your test.Mocks are used on void methods which are verified in the Assert that they are called.

View Article


Answer by Joe Yang for What's the difference between a mock & stub?

I think the most important difference between them is their intentions.Let me try to explain it in WHY stub vs. WHY mockSuppose I'm writing test code for my mac twitter client's public timeline...

View Article

Answer by Dillon Kearns for What's the difference between a mock & stub?

In the codeschool.com course, Rails Testing for Zombies, they give this definition of the terms:StubFor replacing a method with code that returns a specified result.MockA stub with an assertion that...

View Article


Answer by b4da for What's the difference between a mock & stub?

Stubs don't fail your tests, mock can.

View Article

Answer by Sean Copenhaver for What's the difference between a mock & stub?

StubI believe the biggest distinction is that a stub you have already written with predetermined behavior. So you would have a class that implements the dependency (abstract class or interface most...

View Article

Answer by Andy Lin for What's the difference between a mock & stub?

following is my understanding...if you create test objects locally and feed your local service with that, you are using mock object. this will give a test for the method you implemented in your local...

View Article
Browsing all 43 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>