Next Generation Java Testing: TestNG and Advanced Concepts
內容描述
Description
Enterprise Java developers must achieve broader, deeper test coverage,
going beyond unit testing to implement functional and integration testing with
systematic acceptance. Next Generation Java™ Testing
introduces breakthrough Java testing techniques and TestNG, a powerful open
source Java testing platform.
Cédric Beust, TestNG's creator, and leading Java developer Hani Suleiman,
present powerful, flexible testing patterns that will work with virtually any
testing tool, framework, or language. They show how to leverage key Java
platform improvements designed to facilitate effective testing, such as
dependency injection and mock objects. They also thoroughly introduce TestNG,
demonstrating how it overcomes the limitations of older frameworks and enables
new techniques, making it far easier to test today's complex software
systems.
Pragmatic and results-focused, Next Generation Java™
Testing will help Java developers build more robust code for today's
mission-critical environments.
This book
Illuminates the tradeoffs associated with testing, so you can make
better decisions about what and how to test
Introduces TestNG, explains its goals and features, and shows how to
apply them in real-world environments
Shows how to integrate TestNG with your existing code, development
frameworks, and software libraries
Demonstrates how to test crucial code features, such as encapsulation,
state sharing, scopes, and thread safety
Shows how to test application elements, including JavaEE APIs,
databases, Web pages, and XML files
Presents advanced techniques: testing partial failures, factories,
dependent testing, remote invocation, cluster-based test farms, and more
Walks through installing and using TestNG plug-ins for Eclipse, and IDEA
Contains extensive code examples
Whether you use TestNG, JUnit, or another testing framework, the testing
design patterns presented in this book will show you how to improve your tests
by giving you concrete advice on how to make your code and your design more
testable.
Table of
Contents
Foreword xiiiPreface xvAcknowledgments xxiAbout
the Authors xxiii
Chapter 1: Getting
Started 1
Beyond JUnit
3 3JUnit
4 7Designing for
Testability 8TestNG 17Conclusion 21
Chapter 2: Testing Design
Patterns 23
Testing for
Failures 23Factories 34Data-Driven
Testing 39Asynchronous
Testing 67Testing Multithreaded
Code 71Performance
Testing 83Mocks and
Stubs 90Dependent
Testing 103Inheritance and Annotation
Scopes 113Test
Groups 119Code
Coverage 132Conclusion 150
Chapter 3: Enterprise
Testing 153
A Typical Enterprise
Scenario 154A Concrete
Example 157Test
Implementation 160Exploring the Competing
Consumers Pattern 182The Role of
Refactoring 186Conclusion 194
Chapter 4: Java EE
Testing 197
In-Container versus Out-of-Container
Testing 198In-Container
Testing 200Java Naming and Directory
Interface (JNDI) 207Java Database
Connectivity (JDBC) 210Java Transaction API
(JTA) 215Java Messaging Service
(JMS) 219Java Persistence API
(JPA) 225Enterprise Java Beans 3.0
(EJB3) 236Java API for XML Web Services
(JAX-WS) 246Servlets 255XML 262Conclusion 266
Chapter 5:
Integration 269
Guice 280DbUnit 295HtmlUnit 303Selenium 310Swing
UI Testing 312Tests for Painting
Code 316Continuous
Integration 320Conclusion 322
Chapter 6: Extending
TestNG 325
The TestNG
API 325BeanShell 335Method
Selectors 341Annotation
Transformers 346Reports 355Writing
Custom
Annotations 366Conclusion 375
Chapter 7:
Digressions 377
Motivation 377The
TestNG Philosophy 378The Care and Feeding
of Exceptionsv378Stateful Tests 382The
Pitfalls of Test-Driven
Development 385Testing Private
Methods 388Testing versus
Encapsulation 391The Power of
Debuggers 392Logging Best
Practices 394vThe Value of
Time 397Conclusion 399
Appendix A: IDE
Integration 401
Eclipse 401IntelliJ
IDEA 411
Appendix B: TestNG
Javadocs 421
JDK 1.4 and JDK
5 421Shortcut Syntax for JDK 5
Annotations 423Annotation
Javadocs 423The org.testng.TestNG
Class 428The XML
API 432
Appendix C:
testng.xml 435
Overview 436Scopes 437XML
Tags 437
Appendix D: Migrating from
JUnit 449
JUnitConverter 449Integrated
Development Environments 453Incremental
Migration and JUnit Mode 455Converting
JUnit Code 456
Index 471