JUnit in Action, Second Edition
Petar Tahchiev, Felipe Leme, Vincent Massol, Gary Gregoryقیمت نهایی
۴۴٬۰۰۰ تومان۴۹٬۰۰۰ تومان۱۰٪ تخفیف
- تخفیف زماندار−۵٬۰۰۰ تومان
۵٬۰۰۰ تومان صرفهجویی نسبت به قیمت اصلی
نسخه اصلی و اورجینال
بلافاصله پس از خرید، فایل کتاب روی دستگاه شما آمادهٔ دانلود است.
تحویل فوری
پرداخت امن
ضمانت فایل
پشتیبانی
مشخصات کتاب
- سال انتشار
- ۲۰۱۰
- فرمت
- زبان
- انگلیسی
- حجم فایل
- ۹٫۴ مگابایت
- شابک
- 9781935182023، 1935182021
دربارهٔ کتاب
When JUnit was first introduced a decade ago by Kent Beck and Erich Gamma, the Agile movement was in its infancy, "Test Driven Development" was unknown, and unit testing was just starting to move into the typical developer's vocabulary. Today, most developers acknowledge the benefits of unit testing and rely on the increasingly sophisticated tools now available. The recently released JUnit 4.5 represents the state of the art in unit testing frameworks, and provides significant new features to improve the Java development process. JUnit in Action, Second Edition is an up-to-date guide to unit testing Java applications (including Java EE applications) using the JUnit framework and its extensions. This book provides techniques for solving real-world problems such as testing AJAX applications, using mocks to achieve testing isolation, in-container testing for Java EE and database applications, and test automation. Written to help readers exploit JUnit 4.5, the book covers recent innovations such as the new annotations that simplify test writing, improved exception handling, and the new assertion methods. You'll also discover how to use JUnit extensions to test new application styles and frameworks including Ajax, OSGi, and HTML-based presentation layers. Using a sample-driven approach, various unit testing strategies are covered, such as how to unit test EJBs, database applications, and web applications. Also addressed are testing strategies using freely available open source frameworks and tools, and how to unit test in isolation with Mock Objects. The book will also bring you up to speed on the latest thinking in TDD, BDD, Continuous Integration, and other practices related to unit testing. Purchase of the print book comes with an offer of a free PDF, ePub, and Kindle eBook from Manning. Also available is all code from the book. Front cover......Page 1 brief contents......Page 4 contents......Page 6 preface......Page 16 preface to the first edition......Page 18 acknowledgments......Page 20 Gary Gregory......Page 21 about this book......Page 22 Roadmap......Page 23 Code downloads......Page 25 About the title......Page 26 about the authors......Page 27 Team rebOOk ......Page 29 Part 1 – JUnit essentials......Page 31 JUnit jump-start......Page 33 1.1 Proving it works......Page 34 1.2 Starting from scratch......Page 36 1.3 Understanding unit testing frameworks......Page 38 1.5 Setting up JUnit......Page 39 1.6 Testing with JUnit......Page 40 1.7 Summary......Page 43 Exploring core JUnit......Page 44 2.1 Exploring core JUnit......Page 45 2.2 Running parameterized tests......Page 47 2.3.1 Test runner overview......Page 49 2.3.3 Custom test runners......Page 50 2.4.1 Composing a suite of test classes......Page 51 2.4.2 Composing a suite of suites......Page 52 2.4.3 Suites, IDEs, Ant, and Maven......Page 53 2.5 Summary......Page 54 Mastering JUnit......Page 55 3.1.1 Designing the interfaces......Page 56 3.1.2 Implementing the base class......Page 58 3.2.1 Testing the DefaultController......Page 60 3.2.2 Adding a handler......Page 62 3.2.3 Processing a request......Page 65 3.2.4 Improving testProcessRequest......Page 68 3.3 Testing exception handling......Page 70 3.3.1 Simulating exceptional conditions......Page 71 3.3.2 Testing for exceptions......Page 74 3.4 Timeout testing......Page 75 3.5 Introducing Hamcrest matchers......Page 77 3.6 Setting up a project for testing......Page 80 3.7 Summary......Page 82 Software testing principles......Page 83 4.1.3 Detecting regressions and limiting debugging......Page 84 4.1.5 Improving implementation......Page 85 4.1.7 Enabling code coverage and other metrics......Page 86 4.2.1 The four types of software tests......Page 87 4.2.2 The three types of unit tests......Page 90 4.3 Black box versus white box testing......Page 92 4.4 Summary......Page 93 Part 2 – Different testing strategies......Page 94 5.1 Measuring test coverage......Page 95 5.1.1 Introduction to test coverage......Page 96 5.1.2 Introduction to Cobertura......Page 97 5.1.3 Generating test coverage reports......Page 98 5.1.4 Combining black box and white box testing......Page 99 5.2.2 Reduce dependencies......Page 100 5.2.3 Create simple constructors......Page 101 5.2.5 Avoid hidden dependencies and global state......Page 102 5.2.6 Singletons pros and cons......Page 103 5.2.7 Favor generic methods......Page 104 5.2.9 Favor polymorphism over conditionals......Page 105 5.3.1 Adapting the development cycle......Page 106 5.3.2 The TDD two-step......Page 107 5.4 Testing in the development cycle......Page 108 5.5 Summary......Page 111 Coarse-grained testing with stubs......Page 112 6.1 Introducing stubs......Page 113 6.2 Stubbing an HTTP connection......Page 114 6.2.1 Choosing a stubbing solution......Page 116 6.2.2 Using Jetty as an embedded server......Page 117 6.3.1 Setting up the first stub test......Page 118 6.3.2 Testing for failure conditions......Page 122 6.4.1 Producing a custom URL protocol handler......Page 123 6.4.2 Creating a JDK HttpURLConnection stub......Page 125 6.5 Summary......Page 126 Testing with mock objects......Page 127 7.2 Unit testing with mock objects......Page 128 7.3 Refactoring with mock objects......Page 132 7.3.1 Refactoring example......Page 133 7.4 Mocking an HTTP connection......Page 135 7.4.2 Testing a sample method......Page 136 7.4.3 First attempt: easy method refactoring technique......Page 137 7.4.4 Second attempt: refactoring by using a class factory......Page 139 7.5 Using mocks as Trojan horses......Page 141 7.6.1 Using EasyMock......Page 145 7.6.2 Using JMock......Page 149 7.7 Summary......Page 152 8.1 Limitations of standard unit testing......Page 154 8.2 The mock objects solution......Page 155 8.3.1 Implementation strategies......Page 157 8.3.2 In-container testing frameworks......Page 158 8.4.2 Mock objects pros and cons......Page 159 8.4.3 In-container testing pros and cons......Page 161 8.5 Summary......Page 162 Part 3 – JUnit and the build process......Page 163 Running JUnit tests from Ant......Page 164 9.2 Running tests from Ant......Page 165 9.3 Introducing and installing Ant......Page 166 9.4 Ant targets, projects, properties, and tasks......Page 167 9.4.1 The javac task......Page 168 9.4.2 The JUnit task......Page 170 9.5 Putting Ant to the task......Page 171 9.6 Dependency management with Ivy......Page 172 9.7 Creating HTML reports......Page 174 9.8 Batching tests......Page 176 9.9 Summary......Page 178 Running JUnit tests from Maven2......Page 179 10.1.1 Convention over configuration......Page 180 10.1.2 Strong dependency management......Page 181 10.1.3 Maven build lifecycles......Page 182 10.1.4 Plug-in-based architecture......Page 183 10.1.5 The Maven Project Object Model......Page 184 10.2 Setting up a Maven project......Page 186 10.3 Introduction to Maven plug-ins......Page 190 10.3.1 Maven Compiler plug-in......Page 191 10.3.2 Maven Surefire plug-in......Page 192 10.3.3 HTML JUnit reports with Maven......Page 193 10.4 The bad side of Maven......Page 194 10.5 Summary......Page 195 11.1 A taste of continuous integration......Page 196 11.1.1 Continuous integration testing......Page 197 11.2.1 Getting started with CruiseControl......Page 199 11.2.3 The CruiseControl config file explained......Page 200 11.3.2 Installation......Page 206 11.3.3 Configuring Hudson......Page 207 11.3.4 Configuring a project in Hudson......Page 209 11.4 Benefits of continuous integration......Page 211 11.5 Summary......Page 212 Part 4 – JUnit extensions......Page 213 Presentation-layer testing......Page 214 12.2.1 A live example......Page 215 12.3.1 HTML assertions......Page 216 12.3.3 Testing more than one web browser......Page 217 12.3.4 Creating standalone tests......Page 218 12.3.7 Accessing elements by name versus index......Page 220 12.3.8 Accessing elements with references......Page 221 12.3.9 Using XPath......Page 222 12.3.10 Test failures and exceptions......Page 223 12.3.11 Application and internet navigation......Page 224 12.3.12 Testing forms with HtmlUnit......Page 225 12.3.13 Testing frames......Page 227 12.3.14 Testing JavaScript......Page 228 12.3.16 SSL errors......Page 230 12.4.1 Writing tests in Cactus......Page 231 12.5 Introducing Selenium......Page 233 12.6.1 A live example......Page 235 12.7.1 Managing the Selenium server......Page 236 12.7.2 Running Selenium tests with JUnit 4......Page 237 12.8.1 Testing for a specific web browser......Page 240 12.8.2 Testing multiple browsers......Page 241 12.8.3 Application and internet navigation......Page 243 12.8.5 Failing tests with exceptions......Page 244 12.8.7 Testing JavaScript alerts......Page 245 12.8.9 Capturing a screen shot for a JUnit 4 test failure......Page 246 12.9 HtmlUnit versus Selenium......Page 247 12.10 Summary......Page 248 Ajax testing......Page 249 13.1.2 Ajax interaction......Page 250 13.2.1 Functional testing......Page 252 13.2.3 Service testing......Page 253 13.3.1 Functional testing with Selenium......Page 254 13.3.2 Functional testing with HtmlUnit......Page 258 13.4.1 JavaScript testing with RhinoUnit......Page 259 13.4.2 JavaScript testing with JsUnit......Page 262 13.4.3 Writing JsUnit tests......Page 263 13.4.4 Writing JsUnit test suites......Page 264 13.4.5 Running JsUnit tests manually......Page 266 13.4.6 Running JsUnit tests with Ant......Page 267 13.6 Checking best practices with JSLint......Page 270 13.7.1 Calling an XML service......Page 272 13.7.2 Validating an XML response......Page 273 13.7.3 Validating a JSON response......Page 274 13.8.1 Choosing a testing framework for a GWT application......Page 276 13.8.2 Creating a GWTTestCase manually......Page 278 13.8.3 Creating a GWTTestCase with junitCreator......Page 280 13.8.6 Creating a test suite......Page 281 13.9 Summary......Page 282 Server-side Java testing with Cactus......Page 284 14.2.1 Java components that you can test with Cactus......Page 285 14.2.2 General principles......Page 286 14.2.3 How Cactus works......Page 288 14.3 Testing servlets and filters......Page 290 14.3.2 Writing servlet tests with Cactus......Page 291 14.4.3 Unit testing a JSP in isolation with Cactus......Page 298 14.4.4 Executing a JSP with SQL results data......Page 299 14.5 Testing EJBs......Page 302 14.6 What is Cargo?......Page 304 14.7.1 Cactus tasks to prepare the archive......Page 305 14.8.1 Maven2 cactifywar MOJO......Page 310 14.8.2 Maven2 cactifyear MOJO......Page 314 14.9 Executing Cactus tests from the browser......Page 315 14.10 Summary......Page 316 Testing JSF applications......Page 317 15.1 Introducing JSF......Page 318 15.2 Introducing the sample application......Page 319 15.3 Typical problems when testing JSF applications......Page 325 15.4.1 Black box approach......Page 326 15.4.2 Mock objects to the rescue......Page 327 15.5 Testing the sample application with JSFUnit......Page 329 15.5.2 Testing Ajax using JSFUnit......Page 330 15.6 Using HtmlUnit with JSFUnit......Page 332 15.7 Performance testing for your JSF application......Page 333 15.8 Summary......Page 334 Testing OSGi components......Page 335 16.1 Introducing OSGi......Page 336 16.2 Our first OSGi service......Page 337 16.2.1 The sample application......Page 341 16.3 Testing OSGi services......Page 343 16.3.1 Mock objects......Page 344 16.4 Introducing JUnit4OSGi......Page 347 16.5 Summary......Page 350 Testing database access......Page 351 17.1.1 Unit tests must exercise code in isolation......Page 352 17.1.3 Unit tests must be fast to run......Page 353 17.2.1 The sample application......Page 354 17.3 Using datasets to populate the database......Page 355 17.3.1 DatabaseOperation dissected......Page 359 17.4 Asserting database state with datasets......Page 360 17.4.1 Filtering data sets......Page 362 17.4.2 Ignoring columns......Page 363 17.5.1 Using ReplacementDataSet to handle the different IDs issue......Page 365 17.5.2 Handling NULL values......Page 367 17.6 Creating datasets from existing database data......Page 371 17.7.1 DbUnit and the Template Design Pattern......Page 372 17.7.2 Improving reuse through custom annotations......Page 375 17.7.3 Using Expression Language in datasets......Page 378 17.8.2 Make sure the target database is tested......Page 381 17.8.5 Plan your dataset usage......Page 382 17.9 Summary......Page 383 Testing JPA-based applications......Page 385 18.1.1 The sample application......Page 386 18.1.2 Multiple layers, multiple testing strategies......Page 388 18.2 Aspects of JPA testing......Page 391 18.3 Preparing the infrastructure......Page 393 18.4 Testing JPA entities mapping......Page 396 18.4.1 Integrating test cases with JPA ID generators......Page 398 18.5 Testing JPA-based DAOs......Page 404 18.6 Testing foreign key names......Page 410 18.7 Summary......Page 413 JUnit on steroids......Page 414 19.1.1 Tools overview......Page 415 19.2 Transparent mock usage......Page 416 19.2.1 Unitils EasyMock support......Page 417 19.2.2 FEST-Mocks......Page 419 19.2.3 Mycila......Page 420 19.3 DbUnit integration......Page 422 19.4.1 JUnit-addons assertions package......Page 426 19.4.2 Unitils’ ReflectionAssert......Page 428 19.4.3 FEST Fluent Assertions Module......Page 430 19.5.1 In-house alternative......Page 432 19.5.2 JUnit-addons......Page 435 19.5.3 FEST-Reflect......Page 436 19.6 Summary......Page 437 A.1 Global changes......Page 438 A.2.2 Constructors......Page 439 A.3.1 @Before and @After annotations......Page 440 A.3.2 @BeforeClass and @AfterClass annotations......Page 441 A.3.5 Exception testing......Page 442 A.3.6 Timeout testing......Page 443 A.4.2 Test suites......Page 444 A.4.3 Parameterized tests......Page 445 A.5.1 Hamcrest assertions......Page 446 A.5.3 New assertions......Page 447 A.5.4 Assertion errors......Page 448 appendix B: Extending the JUnit API with custom runners and matchers......Page 449 B.2 Implementing a custom runner......Page 450 B.3 Implementing a custom matcher......Page 457 appendix C: The source code for the book......Page 463 C.2 Source code overview......Page 464 C.4 JAR versions......Page 465 C.5 Directory structure conventions......Page 466 D.1 JUnit integration with Eclipse......Page 467 D.1.3 Running JUnit tests from Eclipse......Page 468 D.1.4 Running Ant scripts from Eclipse......Page 469 D.2.1 Integrated in your development cycle......Page 471 D.3.1 Installing NetBeans......Page 472 D.3.2 Setting up NetBeans projects from the source......Page 473 D.3.3 Running JUnit tests from NetBeans......Page 474 D.3.4 Running Ant scripts from NetBeans......Page 476 E.1.1 Standard configuration......Page 477 E.1.2 Eclipse configuration......Page 478 E.2 Configuring Cactus with HtmlUnit......Page 479 E.5 Installing JsUnit......Page 480 A......Page 481 C......Page 482 D......Page 483 E......Page 484 H......Page 485 J......Page 486 L......Page 487 O......Page 488 S......Page 489 T......Page 490 Z......Page 491 Back cover......Page 492 "JUnit in Action, Second Edition is an up-to-date guide to unit testing Java applications (including Java EE applications) using the JUnit framework and its extensions. This book provides techniques for solving real-world problems such as testing AJAX applications, using mocks to achieve testing isolation, in-container testing for Java EE and database applications, and test automation. Written to help readers exploit JUnit 4.5, the book covers recent innovations such as the new annotations that simplify test writing, improved exception handling, and the new assertion methods. You'll also discover how to use JUnit extensions to test new application styles and frameworks including Ajax, OSGi, and HTML-based presentation layers. Using a sample-driven approach, various unit testing strategies are covered, such as how to unit test EJBs, database applications, and web applications. Also addressed are testing strategies using freely available open source frameworks and tools, and how to unit test in isolation with Mock Objects. The book will also bring you up to speed on the latest thinking in TDD, BDD, Continuous Integration, and other practices related to unit testing"--Resource description page.
کتابهای مشابه
JUnit in Action, Second Edition
۴۹٬۰۰۰ تومان
JUnit in Action, Second Edition
۴۹٬۰۰۰ تومان
JUnit in Action
۴۹٬۰۰۰ تومان
JUnit in Action, 2nd edition
۴۹٬۰۰۰ تومان
JUnit in Action, Third Edition
۴۹٬۰۰۰ تومان
JUnit in Action
۴۹٬۰۰۰ تومان
JUnit in Action
۴۹٬۰۰۰ تومان
JUnit in Action, Third Edition - MEAP Version 3
۴۹٬۰۰۰ تومان
JUnit in Action [Java testing framework
۴۹٬۰۰۰ تومان
Docker in Action, Second Edition
۴۹٬۰۰۰ تومان
jQuery in Action, Second Edition
۴۹٬۰۰۰ تومان
jQuery in Action, Second Edition
۴۹٬۰۰۰ تومان
قیمت نهایی
۴۴٬۰۰۰ تومان
