Sprint Challenge: Advanced Testing

Overview

Welcome to the Sprint Challenge for Unit 3 Sprint 11! This challenge will test your understanding of mocking, testing static methods, and AWS Lambda functions. You'll apply all the skills you've learned throughout this sprint to solve complex testing scenarios.

Part 1: Mockito Mastery

In this section, you'll work with a product management system that has several dependencies. Your task is to write comprehensive unit tests using Mockito to verify the system's functionality.

Requirements

  1. Create mock objects for all dependencies of the ProductService class
  2. Write tests for the normal operation paths (retrieving, creating, updating products)
  3. Test exception handling paths (not found, validation errors, etc.)
  4. Use argument captors to verify that the correct data is being passed to dependencies
  5. Verify the correct number of interactions with dependencies

Tips

  • Use @Mock and @InjectMocks annotations to create mocks and inject them
  • Consider using the verify() method to check if methods were called correctly
  • Don't forget to test edge cases and error conditions

Part 2: Testing Static Methods

In this part, you'll work with code that relies on static methods for utility functions and configuration. Your task is to test this code effectively using appropriate techniques.

Requirements

  1. Set up PowerMock to test classes that use static methods
  2. Write tests that mock the behavior of static utility methods
  3. Create a wrapper class for one static utility to improve testability
  4. Refactor a class to use dependency injection instead of direct static method calls
  5. Compare and contrast the different approaches in your comments

Tips

  • Use @RunWith(PowerMockRunner.class) and @PrepareForTest annotations
  • Consider using the PowerMockito.mockStatic() method for direct static mocking
  • Remember that refactoring for testability often improves design overall

Part 3: AWS Lambda Functions

For the final part, you'll work with AWS Lambda functions. Your task is to create effective tests for Lambda functions that interact with AWS services.

Requirements

  1. Implement unit tests for the core business logic of the Lambda functions
  2. Create tests that mock the AWS Lambda Context
  3. Implement tests that verify proper logging is performed
  4. Test error handling and response formatting
  5. Explain your testing strategy in code comments

Tips

  • Focus on testing business logic separate from AWS infrastructure
  • Mock the Context object to verify logging behavior
  • Test both successful execution paths and error handling

Submission Guidelines

  1. Complete all parts of the challenge
  2. Ensure all tests pass
  3. Commit your changes to your fork of the repository
  4. Submit a pull request or follow your instructor's submission guidelines

Grading Criteria

  • Correctness of tests (60%)
  • Code quality and organization (20%)
  • Comprehensive test coverage (20%)

Important Notes

  • Focus on writing clean, readable tests that clearly demonstrate the functionality being tested
  • Remember to follow the Given-When-Then pattern for test clarity
  • Document your tests with clear method names and comments explaining your testing strategy
  • If you get stuck, review the module materials and code-alongs for guidance

Helpful Resources