售 价:¥
温馨提示:数字商品不支持退换货,不提供源文件,不支持导出打印
为你推荐
Test-Driven Java Development
Table of Contents
Test-Driven Java Development
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers, and more
Why subscribe?
Free access for Packt account holders
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Errata
Piracy
Questions
1. Why Should I Care for Test-driven Development?
Why TDD?
Understanding TDD
Red-green-refactor
Speed is the key
It's not about testing
Testing
The black-box testing
The white-box testing
The difference between quality checking and quality assurance
Better tests
Mocking
Executable documentation
No debugging
Summary
2. Tools, Frameworks, and Environments
Git
Virtual machines
Vagrant
Docker
Build tools
The integrated development environment
The IDEA demo project
Unit testing frameworks
JUnit
TestNG
Hamcrest and AssertJ
Hamcrest
AssertJ
Code coverage tools
JaCoCo
Mocking frameworks
Mockito
EasyMock
Extra power for mocks
User interface testing
Web testing frameworks
Selenium
Selenide
The behavior-driven development
JBehave
Cucumber
Summary
3. Red-Green-Refactor – from Failure through Success until Perfection
Setting up the environment with Gradle and JUnit
Setting up Gradle/Java project in IntelliJ IDEA
The red-green-refactor process
Write a test
Run all the tests and confirm that the last one is failing
Write the implementation code
Run all the tests
Refactor
Repeat
The Tic-Tac-Toe game requirements
Developing Tic-Tac-Toe
Requirement 1
Test
Implementation
Test
Implementation
Test
Implementation
Refactoring
Requirement 2
Test
Implementation
Test
Implementation
Test
Requirement 3
Test
Implementation
Test
Implementation
Refactoring
Test
Implementation
Test
Implementation
Test
Implementation
Refactoring
Requirement 4
Test
Implementation
Refactoring
Code coverage
More exercises
Summary
4. Unit Testing – Focusing on What You Do and Not on What Has Been Done
Unit testing
What is unit testing?
Why unit testing?
Code refactoring
Why not use unit tests exclusively?
Unit testing with TDD
TestNG
The @Test annotation
The @BeforeSuite, @BeforeTest, @BeforeGroups, @AfterGroups, @AfterTest, and @AfterSuite annotations
The @BeforeClass and @AfterClass annotations
The @BeforeMethod and @AfterMethod annotations
The @Test(enable = false) annotation argument
The @Test(expectedExceptions = SomeClass.class) annotation argument
TestNG vs JUnit summary
Remote controlled ship requirements
Developing the remote-controlled ship
Project setup
Helper classes
Requirement 1
Specification
Specification implementation
Refactoring
Requirement 2
Specification
Specification implementation
Specification
Specification implementation
Requirement 3
Specification
Specification implementation
Specification
Specification implementation
Requirement 4
Specification
Specification implementation
Specification
Specification implementation
Requirement 5
Specification
Specification implementation
Refactoring
Specification
Specification implementation
Requirement 6
Summary
5. Design – If It's Not Testable, It's Not Designed Well
Why should we care about design?
Design principles
You Ain't Gonna Need It
Don't Repeat Yourself
Keep It Simple, Stupid
Occam's Razor
SOLID
Connect4
Requirements
Test the last implementation of Connect4
Requirement 1
Requirement 2
Requirement 3
Requirement 4
Requirement 5
Requirement 6
Requirement 7
Requirement 8
The TDD implementation of Connect4
Hamcrest
Requirement 1
Tests
Code
Requirement 2
Tests
Code
Requirement 3
Tests
Code
Requirement 4
Tests
Code
Requirement 5
Tests
Code
Requirement 6
Tests
Code
Requirement 7
Tests
Code
Requirement 8
Tests
Code
Summary
6. Mocking – Removing External Dependencies
Mocking
Why mocks?
Terminology
Mock objects
Mockito
The Tic-Tac-Toe v2 requirements
Developing Tic-Tac-Toe v2
Requirement 1
Specification and specification implementation
Specification
Specification implementation
Specification
Implementation
Refactoring
Specification
Specification implementation
Specification
Specification implementation
Refactoring
Specification
Specification implementation
Specification
Specification implementation
Specification
Specification implementation
Specification
Specification implementation
Requirement 2
Specification
Specification implementation
Specification refactoring
Specification
Specification implementation
Specification
Specification implementation
Specification
Specification implementation
Exercises
Integration tests
Tests separation
The integration test
Summary
7. BDD – Working Together with the Whole Team
Different specifications
Documentation
Documentation for coders
Documentation for non-coders
Behavior-driven development
Narrative
Scenarios
The Books Store BDD story
JBehave
JBehave runner
Pending steps
Selenium and Selenide
JBehave steps
Final validation
Summary
8. Refactoring Legacy Code – Making it Young Again
Legacy code
Legacy code example
Other ways to recognize legacy code
A lack of dependency injection
The legacy code change algorithm
Applying the legacy code change algorithm
Identifying change points
Finding test points
Breaking dependencies
Writing tests
The Kata exercise
Legacy Kata
Description
Technical comments
Adding a new feature
Black-box or spike testing
Preliminary investigation
How to find candidates for refactoring
Introducing the new feature
Applying the legacy code algorithm
Writing end-to-end test cases
Automating the test cases
Injecting the BookRepository dependency
Extract and override call
Parameterizing a constructor
Adding a new feature
Removing the primitive obsession with status as Int
Summary
9. Feature Toggles – Deploying Partially Done Features to Production
Continuous Integration, Delivery, and Deployment
Feature Toggles
A Feature Toggle example
Implementing the Fibonacci service
Working with the template engine
Summary
10. Putting It All Together
TDD in a nutshell
Best practices
Naming conventions
Processes
Development practices
Tools
This is just the beginning
This does not have to be the end
Index
买过这本书的人还买过
读了这本书的人还在读
同类图书排行榜