D E V M A T E

Loading

Mocking with Factory Methods

You are here:
Estimated reading time: 1 min

In this tutorial we learn how to use factory methods in Devmate UTST for mocking with a simple code example.

The class to test MockDemo has a field of the interface IDemo. We want to test the method MethodToTest which uses the method getInt of IDemo.

Without an implementation of IDemo we need to mock it. We start devmate normally and create an instance of MockDemo.

Code example of ClassToTest
The class to test MockDemo
Code example of interface for the tested class
Interface to the field of MockDemo

As an interface IDemo cannot be instantiated so we use a factory method instead(image createFactory) (useFactory)

Creating a factory method in Devmate
Creating the factory method
Using a factory method in Devmate
Using the factory method

When we are finished with creating the representants and tests, we can generate the code .

Generate code with factory methods in Devmate
Generating the code

The code is generated without an implementation of the factory method and needs to be edited. We need to create a new mock object of type IDemo and tell it in the setup what it should return when the getInt method is called.

Implementing the factory method
Editing the generated code to implement the factory method

And done. The tests should now run as expected.

Running mocking tests

Was this article helpful?
Dislike 0
Views: 28

Continue reading

Next: Equivalence Class Prediction

We use cookies to give you the best online experience. By agreeing you accept the use of cookies in accordance with our cookie policy.

Privacy Settings saved!
Privacy Settings

When you visit any web site, it may store or retrieve information on your browser, mostly in the form of cookies. Control your personal Cookie Services here.

GetResponse, Google Analytics

We use Google Analytics for marketing purposes. You can disable these cookies.
  • __utmz
  • __utma
  • _ga
  • _gat

We use GetResponse for marketing purposes. This service cannot be disabled, otherwise the website functions will be limited.

Decline all Services
Accept all Services
Get Free Access Now to
9 eBooks!
All about Automated Software Testing
Proven experts
Learn to save up to 75% of your test efforts
Get Free Access Now!
Get Access Now! & Save 50%
Personal Trainer FREE Nutrition Custom Workout App
Get Access Now!
eBook Download
Enter your details to get your free ebook!
All about Automated Software Testing
Download Free Ebook
SUBSCRIBE
MY WEB
NEWSLETTERS
Lorem ipsum dolor sit amet, consectetur adipiscing