Cover image for Mastering Unit Testing Using Mockito and JUnit.
Mastering Unit Testing Using Mockito and JUnit.
Title:
Mastering Unit Testing Using Mockito and JUnit.
Author:
Acharya, Sujoy.
ISBN:
9781783982516
Personal Author:
Physical Description:
1 online resource (321 pages)
Contents:
Mastering Unit Testing Using Mockito and JUnit -- Table of Contents -- Mastering Unit Testing Using Mockito and JUnit -- Credits -- About the Author -- 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 -- Downloading the example code -- Errata -- Piracy -- Questions -- 1. JUnit 4 - a Total Recall -- Defining unit testing -- Working with JUnit 4 -- Setting up Eclipse -- Running the first unit test -- Exploring annotations -- Verifying test conditions with Assertion -- Working with exception handling -- Exploring the @RunWith annotation -- Working with JUnit 4++ -- Ignoring a test -- Executing tests in order -- Learning assumptions -- Exploring the test suite -- Asserting with assertThat -- Comparing matchers - equalTo, is, and not -- Working with compound value matchers - either, both, anyOf, allOf, and not -- Working with collection matchers - hasItem and hasItems -- Exploring string matchers - startsWith, endsWith, and containsString -- Exploring built-in matchers -- Building a custom matcher -- Creating parameterized tests -- Working with parameterized constructors -- Working with parameterized methods -- Giving a name -- Working with timeouts -- Exploring JUnit theories -- Externalizing data using @ParametersSuppliedBy and ParameterSupplier -- Dealing with JUnit rules -- Playing with the timeout rule -- Working with the ExpectedException rule -- Unfolding the TemporaryFolder rule -- Exploring the ErrorCollector rule -- Working with the Verifier rule -- Learning the TestWatcher rule -- Working with the TestName rule -- Handling external resources -- Exploring JUnit categories -- Summary.

2. Automating JUnit Tests -- Continuous Integration -- Benefits of CI -- Gradle automation -- Getting started -- Gradling -- Ordering subtasks using doFirst and doLast -- Default tasks -- The task dependency -- Daemon -- Gradle plugins -- The Eclipse plugin -- The Java plugin -- Maven project management -- Installation -- The Archetype plugin -- The Project Object Model (POM) file -- Project dependency -- The build life cycle -- Compiling the project -- Testing the project -- Packaging the project -- The clean life cycle -- The site life cycle -- Another neat tool (Ant) -- Jenkins -- The Gradle project -- The Maven project -- Building the Ant project -- Summary -- 3. Test Doubles -- Dummy -- Stub -- Fake -- Mock -- Spy -- Summary -- 4. Progressive Mockito -- Working with Mockito -- Why should you use Mockito? -- Qualities of unit testing -- Drinking Mockito -- Configuring Mockito -- Mocking in action -- Mocking objects -- Stubbing methods -- Verifying the method invocation -- Why do we use verify? -- Verifying in depth -- Verifying zero and no more interactions -- Using argument matcher -- Why do we need wildcard matchers? -- The ArgumentMatcher class -- Throwing exceptions -- Stubbing consecutive calls -- Stubbing with an Answer -- Spying objects -- Stubbing void methods -- Capturing arguments with ArgumentCaptor -- Verifying the invocation order -- Changing the default settings -- Resetting mock objects -- Exploring Mockito annotations -- Working with inline stubbing -- Determining mocking details -- Behavior-driven development with Mockito -- Writing tests in BDD style -- The BDD syntax -- Summary -- 5. Exploring Code Coverage -- Understanding code coverage -- Learning the inner details of code instrumentation -- Configuring the Eclipse plugin -- Uncovering the Clover plugin -- Working with the EclEmma plugin -- Examining the eCobertura plugin.

Measuring coverage using Gradle -- Working with the Maven Cobertura plugin -- Running the Cobertura Ant task -- Summary -- 6. Revealing Code Quality -- Understanding the static code analysis -- Working with the Checkstyle plugin -- Exploring the FindBugs plugin -- Working with the PMD plugin -- Monitoring code quality with SonarQube -- Running SonarQube -- Analyzing code with the SonarQube runner -- Improving quality with the Sonar Eclipse plugin -- Monitoring quality with Gradle and SonarQube -- Monitoring quality with Maven and SonarQube -- Monitoring quality with Ant and SonarQube -- Getting familiar with false positives -- Summary -- 7. Unit Testing the Web Tier -- Unit testing servlets -- Building and unit testing a J2EE web application -- Playing with Spring MVC -- Summary -- 8. Playing with Data -- Separating concerns -- Unit testing the persistence logic -- Simplifying persistence with Spring -- Verifying the system integrity -- Writing integration tests with Spring -- Summary -- 9. Solving Test Puzzles -- Working with the legacy code -- Working with testing impediments -- Designing for testability -- Identifying constructor issues -- Realizing initialization issues -- Working with private methods -- Working with final methods -- Exploring static method issues -- Working with final classes -- Learning the new attribute -- Exploring static variables and blocks -- Working with greenfield code -- Summary -- 10. Best Practices -- Writing meaningful tests -- Improving readability -- Breaking everything that could possibly break -- Ignoring simple test cases -- Verifying invalid parameters -- Relying on direct testing -- Staying away from debugging -- Avoiding generic matchers -- Keeping away from @ignore -- Eluding debug messages -- Automating JUnit tests -- Configuring tests -- Running in-memory tests -- Staying away from Thread.sleep.

Keeping unit tests away from the production code -- Avoiding static variables -- Assuming the test execution order -- Loading data from files -- Invoking super.setUp() and super.tearDown() -- Staying away from side effects -- Working with locales -- Working with dates -- Working with assertions -- Using the correct assertion -- Maintaining the assertEquals parameter order -- Striving for one assertion per test -- Handling exceptions -- Working with test smells -- Refactoring duplicates -- Refactoring the test control logic -- Removing the test logic from the production code -- Refactoring over engineered tests -- Summary -- Index.
Abstract:
A practical and easy-to-follow, yet comprehensive, guide to learning advanced JUnit testing. Each topic is explained and placed in context, and for the more inquisitive, there are more details of the concepts used. This book is for you if you are a developer with some experience in Java application development as well as a basic knowledge of JUnit testing. But for those whose skill set is void of any prior experience with JUnit testing, the book also covers basic fundamentals to get you acquainted with the concepts before putting them into practise.
Local Note:
Electronic reproduction. Ann Arbor, Michigan : ProQuest Ebook Central, 2017. Available via World Wide Web. Access may be limited to ProQuest Ebook Central affiliated libraries.
Subject Term:
Electronic Access:
Click to View
Holds: Copies: