Test-Driven Java Development
eBook - ePub

Test-Driven Java Development

Viktor Farcic, Alex Garcia

Condividi libro
  1. 284 pagine
  2. English
  3. ePUB (disponibile sull'app)
  4. Disponibile su iOS e Android
eBook - ePub

Test-Driven Java Development

Viktor Farcic, Alex Garcia

Dettagli del libro
Anteprima del libro
Indice dei contenuti
Citazioni

Informazioni sul libro

Invoke TDD principles for end-to-end application development with Java

About This Book

  • Explore the most popular TDD tools and frameworks and become more proficient in building applications
  • Create applications with better code design, fewer bugs, and higher test coverage, enabling you to get them to market quickly
  • Implement test-driven programming methods into your development workflows

Who This Book Is For

If you're an experienced Java developer and want to implement more effective methods of programming systems and applications, then this book is for you.

What You Will Learn

  • Explore the tools and frameworks required for effective TDD development
  • Perform the Red-Green-Refactor process efficiently, the pillar around which all other TDD procedures are based
  • Master effective unit testing in isolation from the rest of your code
  • Design simple and easily maintainable codes by implementing different techniques
  • Use mocking frameworks and techniques to easily write and quickly execute tests
  • Develop an application to implement behaviour-driven development in conjunction with unit testing
  • Enable and disable features using Feature Toggles

In Detail

Test-driven development (TDD) is a development approach that relies on a test-first procedure that emphasises writing a test before writing the necessary code, and then refactoring the code to optimize it.

The value of performing TDD with Java, one of the most established programming languages, is to improve the productivity of programmers, the maintainability and performance of code, and develop a deeper understanding of the language and how to employ it effectively.

Starting with the basics of TDD and reasons why its adoption is beneficial, this book will take you from the first steps of TDD with Java until you are confident enough to embrace the practice in your day-to-day routine.

You'll be guided through setting up tools, frameworks, and the environment you need, and will dive right in to hands-on exercises with the goal of mastering one practice, tool, or framework at a time. You'll learn about the Red-Green-Refactor procedure, how to write unit tests, and how to use them as executable documentation.

With this book you'll also discover how to design simple and easily maintainable code, work with mocks, utilise behaviour-driven development, refactor old legacy code, and release a half-finished feature to production with feature toggles.

You will finish this book with a deep understanding of the test-driven development methodology and the confidence to apply it to application programming with Java.

Style and approach

An easy-to-follow, hands-on guide to building applications through effective coding practices. This book covers practical examples by introducing different problems, each one designed as a learning exercise to help you understand each aspect of TDD.

Domande frequenti

Come faccio ad annullare l'abbonamento?
È semplicissimo: basta accedere alla sezione Account nelle Impostazioni e cliccare su "Annulla abbonamento". Dopo la cancellazione, l'abbonamento rimarrà attivo per il periodo rimanente già pagato. Per maggiori informazioni, clicca qui
È possibile scaricare libri? Se sì, come?
Al momento è possibile scaricare tramite l'app tutti i nostri libri ePub mobile-friendly. Anche la maggior parte dei nostri PDF è scaricabile e stiamo lavorando per rendere disponibile quanto prima il download di tutti gli altri file. Per maggiori informazioni, clicca qui
Che differenza c'è tra i piani?
Entrambi i piani ti danno accesso illimitato alla libreria e a tutte le funzionalità di Perlego. Le uniche differenze sono il prezzo e il periodo di abbonamento: con il piano annuale risparmierai circa il 30% rispetto a 12 rate con quello mensile.
Cos'è Perlego?
Perlego è un servizio di abbonamento a testi accademici, che ti permette di accedere a un'intera libreria online a un prezzo inferiore rispetto a quello che pagheresti per acquistare un singolo libro al mese. Con oltre 1 milione di testi suddivisi in più di 1.000 categorie, troverai sicuramente ciò che fa per te! Per maggiori informazioni, clicca qui.
Perlego supporta la sintesi vocale?
Cerca l'icona Sintesi vocale nel prossimo libro che leggerai per verificare se è possibile riprodurre l'audio. Questo strumento permette di leggere il testo a voce alta, evidenziandolo man mano che la lettura procede. Puoi aumentare o diminuire la velocità della sintesi vocale, oppure sospendere la riproduzione. Per maggiori informazioni, clicca qui.
Test-Driven Java Development è disponibile online in formato PDF/ePub?
Sì, puoi accedere a Test-Driven Java Development di Viktor Farcic, Alex Garcia in formato PDF e/o ePub, così come ad altri libri molto apprezzati nelle sezioni relative a Informatique e Programmation en Java. Scopri oltre 1 milione di libri disponibili nel nostro catalogo.

Informazioni

Anno
2015
ISBN
9781783987429
Edizione
1
Argomento
Informatique

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

Test-Driven Java Development

Copyright © 2015 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any...

Indice dei contenuti