Test-Driven Development (TDD) using Java
(5 days)
Interactive, hands-on, instructor led, Zoom-based course dates Test-Driven Development using Java:
Call (815)403-3001 or email Webmaster@WSDFirm.com for details or to sign up.
Course Description
Developing better production code is the goal of implementing a Test-Driven Development (TDD) environment. Students will learn to deliver that higher quality solution in this hands-on course. The classic path of build, build, build, then testing after leads to brittle, bug-ridden, challenging-to-improve projects. That “technical debt” is reduced by using test-driven development techniques students will learn in class. Students write tests in hands-on labs and then produce better production code than would be developed by writing the code alone. Attendees will learn, practice, and implement coding strategies proven for projects large and small, greenfield development, and used with legacy code.
Prerequisites
An understanding of Java programming is required.
Course Outline
Why Test?
- Technical debt - defined
- Technical Debt is a balance
- Think twice, write production code once
- Coding speed, feeling safe to produce code quickly
- Long descriptive names for unit tests increase their value
- Three laws of Test-Driven Development
- Squish bugs before they hurt the quality
- Tools for testing
- Testing use cases
- Arrange, Act, Assert pattern
Unit Testing Basics
- Red, Green, Refactor
- @Test and other Java anotations for testing
- JUnit anotations
- Asserts for strings, collections, and exceptions
- Tests can help you create better production code
- Refactoring code for better and easier maintenance
Where to start
- What to test and why
- Instantiation tests – simple does it work
- Negative Conditions – testing what can do wrong is key
- Border Testing – test around a boundary
- Extremes – crazy values can happen
- Delta Tests – testing change
- Evergreen tests - tests that work now and years from now
Unit Testing Details
- Test negative conditions first
- Rules of TDD
- Asserts – when and where
- Matchers
- Test setup and teardown
- Private helper methods
Exception Testing
- When exception should happen
- This exception never happens, but it did
- Exceptions and testing
- Avoid exceptions by testing object equality
Test-Driven Development Patterns
- SOLID principles
- Single responsibility
- Open/Closed Principle
- Liskov substitution
- Interface segregation
- Dependency inversion
- Factory Method testing
- High Cohesion, low coupling
- Single point of maintenance
- Refactoring
Stubs and Drivers
- Test stub – return acceptable values
- Test Double
- Emulate caller with drivers
Mocks and Fakes
- Mocking manually
- Fakes using interfaces
- Mocking frameworks
- Using Mockito
- Lambda expressions for mocking
System, Regression, and User Acceptance Testing
- All testing matters
- System testing and integration testing
- Sampling for testing
- Regression testing – don’t break what already works
- Acceptance Testing -Requirements must be testable, even soft requirements
- Usability testing
Continuous Integration Servers / Automated Testing
- Test runners
- Working with source control
Working with Existing Code Overview - Refactoring
- Refactoring in a production environment
Changing Production Code – Limiting Risks
- Assess risks first
- Base rates - what has happened on ohter projects matters
- Avoidable Risks
- Test to limit Risks
Safely Adding a Feature and Unit Testing
- New feature and TDD
- Reducing technical debt
- Agile manifesto - working software is the primary measure
Seam Model – Find or Create a Seam for Safe Improvement
- Lose vs. tight coupling
- Look for a Seam
- Create a Seam
- Test before the change for safely
Code Coverage – Safely Making changes
- Test coverage is more than a number
- Black-box testing
- White-box testing
- What not to test
- Measuring test coverage
Code Smells and How to Improve Then
- Hard to change/improve code
- Antipatterns – avoid, find, and remove
- Working code can really smell
- Bloaters – the god class, long methods, long parameter lists
- Object-Oriented Abusers – temporary field, switch statement abuse, interface misuse
- Disposables – dead code, duplicate code, lazy Class
- Couplers – Inappropriate intimacy, middlemen
Dependency Breaking – Better Now and in the Future
- One focused unit of work
- Amazon’s microservice revolution
- Testing once dependency is broken
I Don’t Understand the Code… and How to Change it Safely
- Best practices for large projects
Working Effectively with Legacy Code
- Proven patterns to improve code that is in production
- Sprout Method
- Sprout Class
- Wrap Method
- Wrap class
- Pinch point traps - avoidance
- Extract an interface
- Code that is hard to test strategies
Price $2,295.00 per student.
Price $2,295.00 per student. |
|