liveBook · Manning

What you will learn in Test Driven: Practical TDD and Acceptance TDD for Java Developers

Practical TDD and Acceptance TDD for Java Developers

by Lasse Koskela

Chapter by chapter

Chapter 1: Chapter 1. The big picture

Introduces test-driven development as a test-first approach to guiding implementation and design.

1.1 The challenge: solving the right problem right · 1.1.1 Creating poorly written code · 1.1.2 Failing to meet actual needs · 1.2 Solution: being test-driven · 1.2.1 High quality with TDD · 1.2.2 Meeting needs with acceptance TDD · 1.2.3 What’s in it for me? · 1.3 Build it right: TDD · 1.3.1 Test-code-refactor: the heartbeat · 1.3.2 Developing in small increments · 1.3.3 Keeping code healthy with refactoring · 1.3.4 Making sure the software still works · 1.4 Build the right thing: acceptance TDD · 1.4.1 What’s in a name? · 1.4.2 Close collaboration · 1.4.3 Tests as a shared language · 1.5 Tools for test-driven development · 1.5.1 Unit-testing with xUnit · 1.5.2 Test frameworks for acceptance TDD · 1.5.3 Continuous integration and builds · 1.5.4 Code coverage · 1.6 Summary

What you learn in chapter 1 →

Chapter 2: Chapter 2. Beginning TDD

This introduction recaps the test-code-refactor cycle and its benefits before the chapter’s practical TDD example.

2.1 From requirements to tests · 2.1.1 Decomposing requirements · 2.1.2 What are good tests made of? · 2.1.3 Working from a test list · 2.1.4 Programming by intention · 2.2 Choosing the first test · 2.2.1 Creating a list of tests · 2.2.2 Writing the first failing test · 2.2.3 Making the first test pass · 2.2.4 Writing another test · 2.3 Breadth-first, depth-first · 2.3.1 Faking details a little longer · 2.3.2 Squeezing out the fake stuff · 2.4 Let’s not forget to refactor · 2.4.1 Potential refactorings in test code · 2.4.2 Removing a redundant test · 2.5 Adding a bit of error handling · 2.5.1 Expecting an exception · 2.5.2 Refactoring toward smaller methods · 2.5.3 Keeping methods in balance · 2.5.4 Expecting details from an exception · 2.6 Loose ends on the test list · 2.6.1 Testing for performance · 2.6.2 A looming design dead-end · 2.7 Summary

What you learn in chapter 2 →

Chapter 3: Chapter 3. Refactoring in small steps

The introduction frames a template-engine design problem and defines a spike as throwaway prototyping used to explore a potential solution.

3.1 Exploring a potential solution · 3.1.1 Prototyping with spikes · 3.1.2 Learning by writing tests · 3.1.3 Example spike for learning an API · 3.2 Changing design in a controlled manner · 3.2.1 Creating an alternative implementation · 3.2.2 Switching over safely · 3.3 Taking the new design further · 3.3.1 Keeping things compatible · 3.3.2 Making the switchover · 3.4 Summary

What you learn in chapter 3 →

Chapter 4: Chapter 4. Concepts and patterns for TDD

The chapter introduction previews TDD techniques, testing concepts, testable design, unit-testing patterns, and work with legacy code.

4.1 How to write tests and make them pass · 4.1.1 Test-selection strategies · 4.1.2 Implementation strategies · 4.1.3 Prime guidelines for test-driving · 4.2 Essential testing concepts · 4.2.1 Fixtures are the context for tests · 4.2.2 Test doubles stand in for dependencies · 4.2.3 State and interaction-based testing · 4.3 Closer look into test doubles · 4.3.1 Example of a test double · 4.3.2 Stubs, fakes, and mocks · 4.3.3 Mock objects in action · 4.4 Guidelines for testable designs · 4.4.1 Choose composition over inheritance · 4.4.2 Avoid static and the Singleton · 4.4.3 Isolate dependencies · 4.4.4 Inject dependencies · 4.5 Unit-testing patterns · 4.5.1 Assertion patterns · 4.5.2 Fixture patterns · 4.5.3 Test patterns · 4.6 Working with legacy code · 4.6.1 Test-driven legacy development · 4.6.2 Analyzing the change · 4.6.3 Preparing for the change · 4.6.4 Test-driving the change · 4.7 Summary

What you learn in chapter 4 →

Chapter 5: Chapter 5. Test-driving web components

The introduction frames test-driving Java EE web components as a practical challenge and previews approaches for controllers, views, and component-based frameworks.

5.1 MVC in web applications in 60 seconds · 5.2 Taming the controller · 5.2.1 Test-driving Java Servlets · 5.2.2 Test-driving Spring controllers · 5.3 Creating the view test-first · 5.3.1 Test-driving JSPs with JspTest · 5.3.2 Test-driving Velocity templates · 5.4 TDD with component-based web frameworks · 5.4.1 Anatomy of a typical framework · 5.4.2 Fleshing out Wicket pages test-first · 5.5 Summary

What you learn in chapter 5 →

Chapter 6: Chapter 6. Test-driving data access

The introduction motivates test-driving data access by highlighting the importance of persistent data, the shortcomings of manual inspection, and the gap left by faking persistence in business-logic tests.

6.1 Exploring the problem domain · 6.1.1 Data access crosses boundaries · 6.1.2 Separating layers with the DAO pattern · 6.2 Driving data access with unit tests · 6.2.1 Witnessing the tyranny of the JDBC API · 6.2.2 Reducing pain with Spring’s JdbcTemplate · 6.2.3 Closer to test-driven nirvana with Hibernate · 6.3 Writing integration tests before the code · 6.3.1 What is an integration test? · 6.3.2 Selecting the database · 6.4 Integration tests in action · 6.4.1 Writing our first Hibernate integration test · 6.4.2 Creating the database schema · 6.4.3 Implementing the production code · 6.4.4 Staying clean with transactional fixtures · 6.5 Populating data for integration tests · 6.5.1 Populating objects with Hibernate · 6.5.2 Populating data with DbUnit · 6.6 Should I drive with unit or integration tests? · 6.6.1 TDD cycle with integration tests · 6.6.2 Best of both worlds · 6.7 File-system access · 6.7.1 A tale from the trenches · 6.7.2 Practices for testable file access · 6.8 Summary

What you learn in chapter 6 →

Chapter 7: Chapter 7. Test-driving the unpredictable

This introduction previews the challenges of test-driving time-dependent and multithreaded Java code.

7.1 Test-driving time-based functionality · 7.1.1 Example: logs and timestamps · 7.1.2 Abstracting system time · 7.1.3 Testing log output with faked system time · 7.2 Test-driving multithreaded code · 7.2.1 What are we testing for? · 7.2.2 Thread-safety · 7.2.3 Blocking operations · 7.2.4 Starting and stopping threads · 7.2.5 Asynchronous execution · 7.2.6 Synchronization between threads · 7.3 Standard synchronization objects · 7.3.1 Semaphores · 7.3.2 Latches · 7.3.3 Barriers · 7.3.4 Futures · 7.4 Summary

What you learn in chapter 7 →

Chapter 8: Chapter 8. Test-driving Swing

The introduction frames the challenge of choosing what to test-drive in a Swing GUI, where behavior is only one aspect of design.

8.1 What to test in a Swing UI · 8.1.1 Internal plumbing and utilities · 8.1.2 Rendering and layout · 8.1.3 Interaction · 8.2 Patterns for testable UI code · 8.2.1 Classic Model-View-Presenter · 8.2.2 Supervising Controller · 8.2.3 Passive View · 8.3 Tools for testing view components · 8.3.1 Why do we need tools? · 8.3.2 TDD-friendly tools · 8.4 Test-driving a view component · 8.4.1 Laying out the design · 8.4.2 Adding and operating standard widgets · 8.4.3 Drawing custom graphics · 8.4.4 Associating gestures with coordinates · 8.5 Summary

What you learn in chapter 8 →

Chapter 9: Chapter 9. Acceptance TDD explained

The introduction contrasts TDD’s focus on technical quality with acceptance TDD’s focus on delivering functionality that meets customer and business needs.

9.1 Introduction to user stories · 9.1.1 Format of a story · 9.1.2 Power of storytelling · 9.1.3 Examples of user stories · 9.2 Acceptance tests · 9.2.1 Example tests for a story · 9.2.2 Properties of acceptance tests · 9.2.3 Implementing acceptance tests · 9.3 Understanding the process · 9.3.1 The acceptance TDD cycle · 9.3.2 Acceptance TDD inside an iteration · 9.4 Acceptance TDD as a team activity · 9.4.1 Defining the customer role · 9.4.2 Who writes tests with the customer? · 9.4.3 How many testers do we need? · 9.5 Benefits of acceptance TDD · 9.5.1 Definition of “done” · 9.5.2 Cooperative work · 9.5.3 Trust and commitment · 9.5.4 Specification by example · 9.5.5 Filling the gap · 9.6 What are we testing, exactly? · 9.6.1 Should we test against the UI? · 9.6.2 Should we stub parts of our system? · 9.6.3 Should we test business logic directly? · 9.7 Brief overview of available tools · 9.7.1 Table-based frameworks · 9.7.2 Text-based frameworks · 9.7.3 Scripting language-based frameworks · 9.7.4 Homegrown tools · 9.8 Summary

What you learn in chapter 9 →

Chapter 10: Chapter 10. Creating acceptance tests with Fit

The chapter introduces Fit as a framework for collaborative, automated acceptance testing and previews its concepts and use.

10.1 What’s Fit? · 10.1.1 Fit for acceptance TDD · 10.1.2 Test documents contain fixture tables · 10.1.3 Fixtures: combinations of tables and classes · 10.2 Three built-in fixtures · 10.2.1 ColumnFixture · 10.2.2 RowFixture · 10.2.3 ActionFixture · 10.2.4 Extending the built-in fixtures · 10.3 Beyond the built-ins with FitLibrary · 10.3.1 DoFixture · 10.3.2 SetUpFixture · 10.3.3 There’s more · 10.4 Executing Fit tests · 10.4.1 Using a single test document · 10.4.2 Placing all tests in a folder structure · 10.4.3 Testing as part of an automated build · 10.5 Summary

What you learn in chapter 10 →

Chapter 11: Chapter 11. Strategies for implementing acceptance tests

The introduction frames acceptance-test implementation as a choice between testing the whole system and testing at lower levels, considering cost versus value.

11.1 What should acceptance tests test? · 11.1.1 Focus on what’s essential · 11.1.2 Avoid turbulent interfaces · 11.1.3 Cross the fence where it is lowest · 11.2 Implementation approaches · 11.2.1 Going end-to-end · 11.2.2 Crawling under the skin · 11.2.3 Exercising the internals · 11.2.4 Stubbing out the irrelevant · 11.2.5 Testing backdoors · 11.3 Technology-specific considerations · 11.3.1 Programming libraries · 11.3.2 Faceless, distributed systems · 11.3.3 Console applications · 11.3.4 GUI applications · 11.3.5 Web applications · 11.4 Tips for common problems · 11.4.1 Accelerating test execution · 11.4.2 Reducing complexity of test cases · 11.4.3 Managing test data · 11.5 Summary

What you learn in chapter 11 →

Chapter 12: Chapter 12. Adopting TDD

This introduction frames TDD adoption as both a personal change and a process of bringing colleagues aboard.

12.1 What it takes to adopt TDD · 12.1.1 Getting it · 12.1.2 Sense of urgency · 12.1.3 Sense of achievement · 12.1.4 Exhibiting integrity · 12.1.5 Time for change · 12.2 Getting others aboard · 12.2.1 Roles and ability to lead change · 12.2.2 Change takes time · 12.3 How to fight resistance · 12.3.1 Recognizing resistance · 12.3.2 Three standard responses to resistance · 12.3.3 Techniques for overcoming resistance · 12.3.4 Picking our battles · 12.4 How to facilitate adoption · 12.4.1 Evangelize · 12.4.2 Lower the bar · 12.4.3 Train and educate · 12.4.4 Share and infect · 12.4.5 Coach and facilitate · 12.4.6 Involve others by giving them roles · 12.4.7 Destabilize · 12.4.8 Delayed rewards · 12.5 Summary

What you learn in chapter 12 →

Concepts explained in this book

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.