Mockito Tutorial : Learn mocking with 25 Junit Examples

Learn unit testing and mocking with 25 Junit Examples
4.4 (139 ratings)
Instead of using a simple lifetime average, Udemy calculates a
course's star rating by considering a number of different factors
such as the number of ratings, the age of ratings, and the
likelihood of fraudulent ratings.
2,890 students enrolled
$10
$40
75% off
Take This Course
  • Lectures 37
  • Length 4.5 hours
  • Skill Level All Levels
  • Languages English
  • Includes Lifetime access
    30 day money back guarantee!
    Available on iOS and Android
    Certificate of Completion
Wishlisted Wishlist

How taking a course works

Discover

Find online courses made by experts from around the world.

Learn

Take your courses with you and learn anywhere, anytime.

Master

Learn and practice real-world skills and achieve your goals.

About This Course

Published 9/2016 English

Course Description

Writing great unit tests distinguishes good programmers from great programmers. In this course, you will learn how to write great unit tests with Mockito and JUnit.  You take 12 steps with JUnit and 18 steps with Mockito into unit testing proficiency.

Mockito

  • Step 01 : Set up an Eclipse Project with JUnit and Mockito frameworks. First Green Bar.
  • Step 02 : Example to start understanding why we need mocks.
  • Step 03 : What is a stub? Create an unit test using Stub? Disadvantages of Stubs.
  • Step 04 : Your first Mockito code! Hurrah!!! Lets use Mockito to mock TodoService.
  • Step 05 : Stubbing variations with Mockito. A few mockito examples mocking List class : Multiple return values, Argument Matchers and throwing exceptions.
  • Step 06 : Introduction to BDD. Given When Then. BDD Mockito Syntax.
  • Step 07 : How to verify calls on a mock? Verify how many times a method is called. We will add deleteTodo method to the TodoService.
  • Step 08 : How to capture an argument which is passed to a mock?
  • Step 09 : Hamcrest Matchers.
  • Step 10 : Let's simplify things with Mockito Annotations. @Mock, @InjectMocks, @RunWith(MockitoJUnitRunner.class), @Captor
  • Step 11 : JUnit Rules. Using MockitoJUnit.rule() instead of @RunWith(MockitoJUnitRunner.class).
  • Step 12 : Real world Example with Spring
  • Step 13 : What is a spy? How to spy with Mockito?
  • Step 14 : Some Theory : Why does Mockito not allow stubbing final and private methods?
  • Step 15 : Using PowerMock and Mockito to mock a Static Method.
  • Step 16 : Using PowerMock and Mockito to invoke a private Method.
  • Step 17 : Using PowerMock and Mockito to mock a constructor.
  • Step 18 : Good Unit Tests.


JUnit

  • Step 01 : Need for Unit Testing
  • Step 02 : Setting up your First JUnit
  • Step 03 : First Successful JUnit. Green Bar and assertEquals
  • Step 04 : Refactoring Your First JUnit Test
  • Step 05 : Second JUnit Example assertTrue and assertFalse
  • Step 06 : @Before @After
  • Step 07 : @BeforeClass @AfterClass
  • Step 08 : Comparing Arrays in JUnit Tests
  • Step 09 : Testing Exceptions in JUnit Tests
  • Step 10 : Testing Performance in JUnit Tests
  • Step 11 : Parameterized Tests
  • Step 12 : Organize JUnits into Suites

What are the requirements?

  • You are expected to be familiar with Java
  • You are NOT expected to have any experience with Eclipse or Maven
  • We will help you install Eclipse and get up and running with Maven

What am I going to get from this course?

  • Use Mockito to write great unit tests
  • Understand the basics of unit testing
  • Understand how to use JUnit and Mockito together

Who is the target audience?

  • Students who want to learn unit testing with Junit
  • Students who want to learn mocking with Mockito
  • We will help you install Eclipse and Maven

What you get with this course?

Not for you? No problem.
30 day money back guarantee.

Forever yours.
Lifetime access.

Learn on the go.
Desktop, iOS and Android.

Get rewarded.
Certificate of completion.

Curriculum

Section 1: Introduction
Introduction
Preview
02:18
Three thing you need to know
Preview
01:45
Section 2: Unit Testing with JUnit
JUnit Step 1 : Why is Unit Testing Important?
Preview
03:41
JUnit Step 2 : Setting up your first JUnit
Preview
08:05
Step 03 : First Successful JUnit. Green Bar and assertEquals
09:39
Step 04 : Refactoring Your First JUnit Test
07:44
Step 05 : Second JUnit Example assertTrue and assertFalse
14:45
Step 06 : @Before @After
07:02
Step 07 : @BeforeClass @AfterClass
03:30
Step 08 : Comparing Arrays in JUnit Tests
05:19
Step 09 : Testing Exceptions in JUnit Tests
03:33
Step 10 : Testing Performance in JUnit Tests
04:03
Step 11 : Parameterized Tests
11:11
Step 12 : Organize JUnits into Suites
03:24
Section 3: Getting Ready for Mockito
An Overview
01:53
Mockito Step 01 : Setting up a Maven Project
07:31
Section 4: Need For Mockito
Overview of this Section
02:10
Mockito Step 02 : Setting up SUT (System Under Test)
11:02
Step 03 : Stubbing Example - with Disadvantages of Stubbing
11:43
Step 04 : Your first Mockito code! Hurrah!!!
18:54
Section 5: Mockito Basics
Basics of Mockito - Section Overview
01:05
Step 05 : Stubbing variations with Mockito - Argument Matchers & More...
13:04
Step 06 : BDD Style - Given When Then
13:28
Step 07 : Verify calls on Mocks
08:52
Step 08 : Capturing arguments passed to a Mock
08:43
Section 6: Mockito Advanced
Step 09 : Hamcrest Matchers
11:41
Step 10 : Mockito Annotations - @Mock, @InjectMocks, @RunWith, @Captor..
10:00
Step 11 : Mockito Junit Rule
03:40
Step 12 : Real world Mockito Example with Spring
16:08
Step 13 : Mockito Spy
10:03
Step 14 : Theory : Why does Mockito not allow stubbing final & private methods?
04:25
Section 7: Powermock with Mockito
Step 15 : Setting up PowerMock and SystemUnderTest
08:37
Step 15 : Continued. Mocking Static Method
12:31
Step 16 : Invoking Private Methods
05:43
Step 17 : Mocking a Constructor
09:25
Step 18 : Writing Good Unit Tests
07:22
Bonus Lecture : Our Best Courses
00:14

Students Who Viewed This Course Also Viewed

  • Loading
  • Loading
  • Loading

Instructor Biography

in28Minutes Official, Architect, Programmer and Trainer

About Me

I'm Ranga Karanam, an Architect with 15 Years of Java programming and design  with major banking clients across the world. 

We started in28Minutes with the aim to create Hands-on Courses with Real World Projects. Step-By-Step series of Courses is one of our creations.

About in28Minutes

We use Problem-Solution based Step-By-Step Hands-on Approach With Practical, Real World Application Examples.

While our primary expertise is on Development, Design & Architecture of Java & Related Frameworks (Spring, Spring MVC, Struts, Hibernate) we are expanding into the front-end world (Bootstrap, JQuery, Angular JS).

Our Beliefs

Best Courses are interactive and fun.

Foundations for building high quality applications are best laid down while learning.

Our Approach

We love open source and therefore, All our code is open source too and available on Github.

We use 80-20 Rule. We discuss 20% things used 80% of time in depth. We touch upon other things briefly equipping you with enough knowledge to find out more on your own.

Problem Solution based Step by Step Hands-on Learning.

Ready to start learning?
Take This Course