课程费用

6800.00 /人

课程时长

2

成为教练

课程简介

Mock objects are a powerful tool for unit testing in complex modern software systems. But mock object testing is also misunderstood by many developers who struggle to use mocks to create elegant, maintainable tests.

Based on Dr. McMaster's book, "Mock Object Testing with Examples Using EasyMock", this class will reveal how mock objects are used across the entire expect-use-verify cycle of unit testing.

目标收益

培训对象

课程大纲

Dependencies and Unit Testing 1. Testability
2. Testing modules in isolation
3. Dependency injection
4. Refactoring for dependency injection
5. Test doubles
a. Stubs
b. Mocks
Mocking Dependencies from Scratch 1. Pattern for mock object tests
a. Expect
b. Use
c. Verify
2. Building a mock without using a framework
3. Recording expectations
4. Replaying expectations
5. How to verify
Introducing Mock Object Frameworks 1. Design and implementation goals of a mock object framework
2. Our first mock object framework test case
3. Using annotations
4. Base class for mock object testing
Types of Mocks 1. Strict mocks
2. Nice mocks
3. Choosing the type of mock to use
Matching 1. What are matchers?
2. Strong and weak equality matchers
3. Boolean and comparison matchers
4. Custom matchers
Expectations 1. Expecting calls to void methods
2. Counting calls
a. Expecting a specific number of calls
b. Expecting a range of numbers
c. Expecting no calls
Mocking Results 1. Getting return values from mock methods
2. Stubbing return values
3. Calculating return values on the fly
4. Mocking exceptions
Verification 1. Verifying calls were made with:
a. Specific parameters
b. In a specific order
c. A certain number of times
2. Verifying a mock was never called
3. Automatically verifying at the end of a test case
Partial Mocks 1. Mocking classes rather than interfaces
2. Only mocking certain methods on a class with partial mocks
3. Spying
4. Limitations to partial mocking
Captures 1. Capturing parameter values in mock method calls
2. Why use captures?
a. Verifying multiple method calls
b. Especially complex input parameters
To Mock or Not? 1. Too many interfaces?
2. Dependency injection is hard?
3. Test code mirrors the implementation code?
Dependencies and Unit Testing
1. Testability
2. Testing modules in isolation
3. Dependency injection
4. Refactoring for dependency injection
5. Test doubles
a. Stubs
b. Mocks
Mocking Dependencies from Scratch
1. Pattern for mock object tests
a. Expect
b. Use
c. Verify
2. Building a mock without using a framework
3. Recording expectations
4. Replaying expectations
5. How to verify
Introducing Mock Object Frameworks
1. Design and implementation goals of a mock object framework
2. Our first mock object framework test case
3. Using annotations
4. Base class for mock object testing
Types of Mocks
1. Strict mocks
2. Nice mocks
3. Choosing the type of mock to use
Matching
1. What are matchers?
2. Strong and weak equality matchers
3. Boolean and comparison matchers
4. Custom matchers
Expectations
1. Expecting calls to void methods
2. Counting calls
a. Expecting a specific number of calls
b. Expecting a range of numbers
c. Expecting no calls
Mocking Results
1. Getting return values from mock methods
2. Stubbing return values
3. Calculating return values on the fly
4. Mocking exceptions
Verification
1. Verifying calls were made with:
a. Specific parameters
b. In a specific order
c. A certain number of times
2. Verifying a mock was never called
3. Automatically verifying at the end of a test case
Partial Mocks
1. Mocking classes rather than interfaces
2. Only mocking certain methods on a class with partial mocks
3. Spying
4. Limitations to partial mocking
Captures
1. Capturing parameter values in mock method calls
2. Why use captures?
a. Verifying multiple method calls
b. Especially complex input parameters
To Mock or Not?
1. Too many interfaces?
2. Dependency injection is hard?
3. Test code mirrors the implementation code?

课程费用

6800.00 /人

课程时长

2

预约体验票 我要分享

近期公开课推荐

近期公开课推荐

提交需求