O'Reilly logo

TestNg Beginner's Guide by Varun Menon

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Mocking

Mocking is mainly used while performing unit testing. While writing unit tests, the code under test may depend on another class object or class method in the code. This dependent code may or may not be available for testing. To isolate the behavior of the code under test from that of the dependent code we use the mocking technique.

Mocking allows users to create mock objects and behaviors that the code under test is dependent upon. Mock objects basically simulate the behavior of the dependent code so that the unit testing of the code under test can be completed.

Different mocking strategies

There are a lot of mocking utilities available online for mocking while writing unit tests developed in Java. Each has some advantages and disadvantages ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required