Course: Unit Testing With Mocks
duration: 9 hours |
Language: English (US) |
access duration: 90 days |
Details
In this course, you will get to work with the Java framework Mockito. When performing unit tests on an object, you often have other, complex objects that the object under test depends on. Instead of using those complex objects, you can use Mockito to create mocks of those objects. This way you can mimic their methods to simulate expected behavior.
In this course, you will learn to master mocking and its relationship to unit testing. You will learn to identify situations where the use of mocks is recommended. You will learn to build mocks and you will learn to simulate methods using Mockito. In addition, you will learn to use the mock objects in unit tests.
With Mockito it is also possible to verify aspects of the interaction between the object to be tested and the mock. You will therefore learn how to build mocks using annotations. In addition, you will learn to use the mocks to perform dependency injection in the object. This allows objects to exchange data without their relationship being hard-defined.
Finally, you explore spies. Unlike a mock, which has no real state and in which all behavior must be mimicked, a spy is built on top of a real object of the class being mocked. In addition, a spy has almost full functionality. You will learn to use spies correctly, mock exceptions and test their handling. In addition, you will learn to mock void methods and use argument captors.
Result
Upon successful completion of this course, you will be able to use Mockito during unit testing. You will know when to use mocks and spies and be able to apply them correctly.
Prerequisites
You have knowledge of the Java programming language and have experience performing unit tests.
Target audience
Tester
Content
Unit Testing With Mocks
Unit Testing with Mocks: Getting Started with Mockito
Mockito is a Java framework for building mocks during unit
- testing. When performing unit tests on an object, you often have
- other, complex objects that the object under test depends upon.
- Rather than using those complex objects, you can use Mockito to
- create mocks of those objects and stub their methods to simulate
- expected behavior. Use this course to get to grips with mocking and
- its relationship with unit testing. Set up a Maven project and add
- the required Mockito and JUnit dependencies. Create mocks of
- built-in classes, such as the ArrayList, and built-in interfaces,
- such as the Comparator. Then, work with stub methods using
- Mockito’s when().thenReturn() syntax. When you're done, you'll be
- able to identify situations where using mocks is a good idea,
- construct mocks, stub methods in them using Mockito, and use mock
- objects in unit tests.
Unit Testing with Mocks: Creating Mocks & Verifying Behavior
- Mocks built in Mockito do more than just simulate the behavior of complex objects that your object under test depends upon. Mockito makes it easy for you to verify specific aspects of how the object under test and the mock interact.
- In this course, learn how to build mocks using annotations and use them to perform dependency injection into the object. Then, learn how to work with constructor, setter property, and field injection.
- Moving along, verify the behavior of the object under test and its interaction with the mock using Mockito constructs, such as verify(), verifyNoInteractions(), and various argument matchers.
- When you're done, you'll be able to use annotations to construct mocks in a clean and simple manner and test very specific aspects of the interactions between the stubs in your mocks and the object under test.
Unit Testing with Mocks: Mocking Exceptions & Using Spies
- Unlike a mock, which has no real state, and in which all behavior must be stubbed, a spy is built atop a real object of the class being mocked and has almost full functionality. Only specific methods of the spy are stubbed, which is useful if it is too complex or cumbersome to mock.
- Use this course to learn how to identify when spies are a better choice than mocks, how to construct spies and stub specific methods, and how to raise exceptions in stubbed methods of your mocks. Then, use different methods to check how the object under test copes with those exceptions.
- Moving on, learn how to stub void methods and when to make use of the doNothing().when() syntax.
- When you're done, you'll be able to correctly use spies, mock exceptions and test their handling, mock void methods, and use argument captors.
Course options
We offer several optional training products to enhance your learning experience. If you are planning to use our training course in preperation for an official exam then whe highly recommend using these optional training products to ensure an optimal learning experience. Sometimes there is only a practice exam or/and practice lab available.
Optional practice exam (trial exam)
To supplement this training course you may add a special practice exam. This practice exam comprises a number of trial exams which are very similar to the real exam, both in terms of form and content. This is the ultimate way to test whether you are ready for the exam.
Optional practice lab
To supplement this training course you may add a special practice lab. You perform the tasks on real hardware and/or software applicable to your Lab. The labs are fully hosted in our cloud. The only thing you need to use our practice labs is a web browser. In the LiveLab environment you will find exercises which you can start immediately. The lab enviromentconsist of complete networks containing for example, clients, servers,etc. This is the ultimate way to gain extensive hands-on experience.
Sign In
WHY_ICTTRAININGEN
Via ons opleidingsconcept bespaar je tot 80% op trainingen
Start met leren wanneer je wilt. Je bepaalt zelf het gewenste tempo
Spar met medecursisten en profileer je als autoriteit in je vakgebied.
Ontvang na succesvolle afronding van je cursus het officiële certificaat van deelname van Icttrainingen.nl
Krijg inzicht in uitgebreide voortgangsinformatie van jezelf of je medewerkers
Kennis opdoen met interactieve e-learning en uitgebreide praktijkopdrachten door gecertificeerde docenten
Orderproces
Once we have processed your order and payment, we will give you access to your courses. If you still have any questions about our ordering process, please refer to the button below.
read more about the order process
Een zakelijk account aanmaken
Wanneer u besteld namens uw bedrijf doet u er goed aan om aan zakelijk account bij ons aan te maken. Tijdens het registratieproces kunt u hiervoor kiezen. U heeft vervolgens de mogelijkheden om de bedrijfsgegevens in te voeren, een referentie en een afwijkend factuuradres toe te voegen.
Betaalmogelijkheden
U heeft bij ons diverse betaalmogelijkheden. Bij alle betaalopties ontvangt u sowieso een factuur na de bestelling. Gaat uw werkgever betalen, dan kiest u voor betaling per factuur.
Cursisten aanmaken
Als u een zakelijk account heeft aangemaakt dan heeft u de optie om cursisten/medewerkers aan te maken onder uw account. Als u dus meerdere trainingen koopt, kunt u cursisten aanmaken en deze vervolgens uitdelen aan uw collega’s. De cursisten krijgen een e-mail met inloggegevens wanneer zij worden aangemaakt en wanneer zij een training hebben gekregen.
Voortgangsinformatie
Met een zakelijk account bent u automatisch beheerder van uw organisatie en kunt u naast cursisten ook managers aanmaken. Beheerders en managers kunnen tevens voortgang inzien van alle cursisten binnen uw organisatie.
What is included?
Certificate of participation | Yes |
Monitor Progress | Yes |
Award Winning E-learning | Yes |
Mobile ready | Yes |
Sharing knowledge | Unlimited access to our IT professionals community |
Study advice | Our consultants are here for you to advice about your study career and options |
Study materials | Certified teachers with in depth knowledge about the subject. |
Service | World's best service |
Platform
Na bestelling van je training krijg je toegang tot ons innovatieve leerplatform. Hier vind je al je gekochte (of gevolgde) trainingen, kan je eventueel cursisten aanmaken en krijg je toegang tot uitgebreide voortgangsinformatie.
FAQ
Niet gevonden wat je zocht? Bekijk alle vragen of neem contact op.