Stub or Mock in JUnit

Stub or Mock in JUnit

What is stub and Mock in JUnit? Please give one real time example so that i can understand easily.

View Answers

December 6, 2010 at 5:33 PM

Consider a situation, where you have a class Calculator, that needs a dao (Data Access Object) object to load the data it needs from a database. Setting up the connection and inserting the data in the database can be a lot of work.

Instead you can provide the Calculator instance with a fake dao class which just returns the data you need for the test. The fake dao class will not actually read the data from the database. The fake dao class is a mock object or stub object.

Ads









Related Tutorials/Questions & Answers:
spring with junit and mock testing
spring with junit and mock testing  spring with junit mock testing
junit
junit  i want to learn junit for user guidence for easy format to understnad to study. please provide that one
Advertisements
junit
junit  Explain about junit?   Junit is new framework designed for Java to perform unit testing. It is an Open source framework. Junit... ). It helps the developers in designing and writing test cases. Junit also have
Junit
Junit  hii.... how to create junit of methods having parameters passed in it..... for example : plz dont refer any link. Just help me by junit of this code. public boolean validateUser(final Display display) { int
Junit
) { UniversalData.connectionDetails = connectionDetails; }** if i want to make a test case using Junit...; regards Ankit Chauhan   Have a look at the following link: Junit Testing
junit - JUNIT
junit  can u give me a sample application of using junit?  Hi Friend, Please visit the following link: http://www.roseindia.net/junit/ Hope that it will be helpful for you. Thanks
Using Spring mock objects
Using Mock objects Mock Object is object that mimic/copy some real object... object. It originally became popular by the junit team and the expert programmers/developers. The mock object simulate the behavior of real, complex
Version of junit>junit dependency
List of Version of junit>junit dependency
ModuleNotFoundError: No module named 'stub'
ModuleNotFoundError: No module named 'stub'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'stub' How to remove the ModuleNotFoundError: No module named 'stub' error
ModuleNotFoundError: No module named 'stub'
ModuleNotFoundError: No module named 'stub'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'stub' How to remove the ModuleNotFoundError: No module named 'stub' error
ModuleNotFoundError: No module named 'mock'
ModuleNotFoundError: No module named 'mock'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'mock' How to remove the ModuleNotFoundError: No module named 'mock' error
Junit
JUnit Junit is new framework designed for Java to perform unit testing. It is an Open source framework. Junit is an instance of xUnit architecture... and writing test cases. Junit also have a Graphical User Interface which allows
Version of junit>junit-dep dependency
List of Version of junit>junit-dep dependency
Version of directory-asn1>stub-compiler dependency
List of Version of directory-asn1>stub-compiler dependency
Version of cn.leancloud>android-stub dependency
List of Version of cn.leancloud>android-stub dependency
ModuleNotFoundError: No module named 'django-stub'
ModuleNotFoundError: No module named 'django-stub'  Hi, My Python... 'django-stub' How to remove the ModuleNotFoundError: No module named 'django-stub' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'lessrpc-stub'
ModuleNotFoundError: No module named 'lessrpc-stub'  Hi, My Python... 'lessrpc-stub' How to remove the ModuleNotFoundError: No module named 'lessrpc-stub' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'pytest-stub'
ModuleNotFoundError: No module named 'pytest-stub'  Hi, My Python... 'pytest-stub' How to remove the ModuleNotFoundError: No module named 'pytest-stub' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'sklearn-stub'
ModuleNotFoundError: No module named 'sklearn-stub'  Hi, My Python... 'sklearn-stub' How to remove the ModuleNotFoundError: No module named 'sklearn-stub' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'swagger-stub'
ModuleNotFoundError: No module named 'swagger-stub'  Hi, My Python... 'swagger-stub' How to remove the ModuleNotFoundError: No module named 'swagger-stub' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'swagger-stub'
ModuleNotFoundError: No module named 'swagger-stub'  Hi, My Python... 'swagger-stub' How to remove the ModuleNotFoundError: No module named 'swagger-stub' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'uwsgi-stub'
ModuleNotFoundError: No module named 'uwsgi-stub'  Hi, My Python... 'uwsgi-stub' How to remove the ModuleNotFoundError: No module named 'uwsgi-stub' error? Thanks   Hi, In your python environment you
What is JUnit?
What is JUnit?  What is the use of JUnit? How to write program to test a Java application? Thanks   Hi, JUnit is unit testing tool in Java. You can use the JUnit to test your Java code. Read more at JUnit 4.3.1
Version of spring>spring-mock dependency
List of Version of spring>spring-mock dependency
Version of springframework>spring-mock dependency
List of Version of springframework>spring-mock dependency
Version of com.amitinside>com.amitinside.sling.testing.osgi-mock dependency
List of Version of com.amitinside>com.amitinside.sling.testing.osgi-mock dependency
Version of com.fiftyonred>mock-jedis dependency
List of Version of com.fiftyonred>mock-jedis dependency
Version of com.headius>coro-mock dependency
List of Version of com.headius>coro-mock dependency
Version of com.headius>unsafe-mock dependency
List of Version of com.headius>unsafe-mock dependency
Version of com.statemachinesystems>mock-clock dependency
List of Version of com.statemachinesystems>mock-clock dependency
Version of com.tacitknowledge>jcr-mock dependency
List of Version of com.tacitknowledge>jcr-mock dependency

Ads