Junit in Action (MEAP) [Third ed.]

1,807 310 24MB

English Pages 525 [534] Year 2020

Report DMCA / Copyright

DOWNLOAD FILE

Junit in Action (MEAP) [Third ed.]

Table of contents :
jUnit in Action, Third Edition MEAP V02
Copyright
Welcome
Brief contents
Chapter 1: JUnit jump-start
1.1 Proving that a program works
1.2 Starting from scratch
1.2.1 Understanding unit testing frameworks
1.2.2 Adding unit tests
1.3 Setting up JUnit
1.4 Testing with JUnit
1.5 Summary
Chapter 2: Exploring core JUnit
2.1 Core annotations
2.1.1 The @DisplayName annotation
2.1.2 The @Disabled annotation
2.2 Nested tests
2.3 Tagged tests
2.4 Assertions
2.5 Assumptions
2.6 Dependency injection in JUnit 5
2.6.1 TestInfoParameterResolver
2.6.2 TestReporterParameterResolver
2.6.3 RepetitionInfoParameterResolver
2.7 Repeated tests
2.8 Parameterized tests
2.9 Dynamic tests
2.10 Using Hamcrest matchers
2.11 Summary
Chapter 3: JUnit architecture
3.1 The concept and importance of software architecture
3.1.1 Story 1 – the telephone directories books
3.1.2 Story 2 – the sneakers manufacturing company
3.2 JUnit 4 architecture
3.2.1 JUnit 4 modularity
3.2.2 JUnit 4 runners
3.2.3 JUnit 4 rules
3.2.4 Shortcomings of the JUnit 4 architecture
3.3 JUnit 5 architecture
3.3.1 JUnit 5 modularity
3.3.2 JUnit 5 platform
3.3.3 JUnit 5 Jupiter
3.3.4 JUnit 5 Vintage
3.3.5 The big picture of the JUnit 5 architecture
3.4 Summary
Chapter 4: Migrating from JUnit 4 to JUnit 5
4.1 The steps between JUnit 4 and JUnit 5
4.2 Needed dependencies
4.3 Annotations, classes, and methods
4.3.1 Rules vs. the extension model
4.3.2 Custom rules
4.4 Summary
Chapter 5: Software testing principles
5.1 The need for unit tests
5.1.1 Allowing greater test-coverage
5.1.2 Increasing team productivity
5.1.3 Detecting regressions and limiting debugging
5.1.4 Refactoring with confidence
5.1.5 Improving implementation
5.1.6 Documenting expected behavior
5.1.7 Enabling code coverage and other metrics
5.2 Test types
5.2.1 Unit testing
5.2.2 Integration software testing
5.2.3 System software testing
5.2.4 Acceptance software testing
5.3 Black-box vs. white-box testing
5.3.1 Black-box testing
5.3.2 White-box testing
5.4 Summary
Chapter 6: Test quality
6.1 Measuring test coverage
6.1.1 Introduction to test coverage
6.1.2 Code coverage measuring tools
6.2 Writing testable code
6.2.1 Understand that public APIs are contracts
6.2.2 Reduce dependencies
6.2.3 Create simple constructors
6.2.4 Follow the Law of Demeter (Principle of Least Knowledge)
6.2.5 Avoid hidden dependencies and global state
6.2.6 Favor generic methods
6.2.7 Favor composition over inheritance
6.2.8 Favor polymorphism over conditionals
6.3 Test Driven Development
6.3.1 Adapting the development cycle
6.3.2 Doing the TDD two-step
6.4 Behavior Driven Development
6.5 Mutation testing
6.6 Testing in the development cycle
6.7 Summary
Chapter 7: Coarse-grained testing with stubs
7.1 Introducing stubs
7.2 Stubbing an HTTP connection
7.2.1 Choosing a stubbing solution
7.2.2 Using Jetty as an embedded server
7.3 Stubbing the web server resources
7.3.1 Setting up the first stub test
7.3.2 Reviewing the first stub test
7.4 Stubbing the connection
7.4.1 Producing a custom URL protocol handler
7.4.2 Creating a JDK HttpURLConnection stub
7.4.3 Running the test
7.5 Summary
Chapter 8: Testing with mock objects
8.1 Introducing mock objects
8.2 Unit testing with mock objects
8.3 Refactoring with mock objects
8.3.1 Refactoring example
8.3.2 Refactoring considerations
8.4 Mocking an HTTP connection
8.4.1 Defining the mock objects
8.4.2 Testing a sample method
8.4.3 Try #1: easy method refactoring technique
8.4.4 Try #2: refactoring by using a class factory
8.5 Using mocks as Trojan horses
8.6 Introducing Mock frameworks
8.6.1 Using EasyMock
8.6.2 Using JMock
8.6.3 Using Mockito
8.7 Summary
Chapter 9: In-container testing
9.1 Limitations of standard unit testing
9.2 The mock-objects solution
9.3 The step to in-container testing
9.3.1 Implementation strategies
9.3.2 In-container testing frameworks
9.4 Comparing stubs, mock objects, and in-container testing
9.4.1 Stubs evaluation
9.4.2 Mock-objects evaluation
9.4.3 In-container testing evaluation
9.5 Testing with Arquillian
9.6 Summary
Chapter 10: Running JUnit tests from Maven 3
10.1 Setting up a Maven project
10.2 Using the Maven plugins
10.2.1 Maven compiler plugin
10.2.2 Maven surefire plugin
10.2.3 HTML JUnit reports with Maven
10.3 Putting it all together
10.4 Maven challenges
10.5 Summary
Chapter 11: Running JUnit tests from Gradle 6
11.1 Introducing Gradle
11.2 Setting up a Gradle project
11.3 Using Gradle plugins
11.4 Creating a Gradle project from the scratch and testing it with JUnit 5
11.5 Comparing Gradle and Maven
11.6 Summary
Chapter 12: JUnit 5 IDE support
12.1 Introducing IDEs
12.2 Using JUnit 5 with IntelliJ IDEA
12.3 Using JUnit 5 with Eclipse
12.4 Using JUnit 5 with NetBeans
12.5 Comparing JUnit 5 usage in IntelliJ, Eclipse, and NetBeans
12.6 Summary
Chapter 13: Continuous integration with JUnit 5
13.1 Continuous integration testing
13.2 Introducing Jenkins
13.3 Jenkins customization
13.4 Practicing continuous integration in a team
13.5 Configuring Jenkins
13.6 Working on tasks in a continuous integration environment
13.7 Summary
Chapter 14: JUnit 5 extension model
14.1 Introducing the JUnit 5 extension model
14.2 Creating the first JUnit 5 extension
14.3 Writing JUnit 5 tests using the available extension points
14.3.1 Persisting the passengers to a database
14.3.2 Checking the unicity of the passengers
14.4 Summary
Chapter 15: Presentation Layer Testing
15.1 Choosing a Testing Framework
15.2 Introducing HtmlUnit
15.2.1 A live example
15.3 Writing HtmlUnit tests
15.3.1 HTML Assertions
15.3.2 Testing for a specific web browser
15.3.3 Testing more than one web browser
15.3.4 Creating stand-alone tests
15.3.5 Testing forms
15.3.6 Testing JavaScript
15.4 Introducing Selenium
15.5 Writing Selenium Tests
15.5.1 Testing for a specific web browser
15.5.2 Testing navigation using a web browser
15.5.3 Testing more than one web browser
15.5.4 Testing Google search and navigation using different web browsers
15.5.5 Testing the authentication scenario to a website
15.6 HtmlUnit vs. Selenium
15.7 Summary
Chapter 16: Testing Spring applications
16.1 Introducing the Spring Framework
16.2 Introducing Dependency Injection
16.3 The first steps to using and testing a Spring application
16.3.1 Creating the Spring context programmatically
16.3.2 Using the Spring TestContext framework
16.4 Using the SpringExtension for JUnit Jupiter
16.5 Adding a new feature and testing it with JUnit 5
16.6 Summary
Chapter 17: Testing Spring Boot applications
17.1 Introducing Spring Boot
17.2 Creating a project with Spring Initializr
17.3 Moving the Spring application to Spring Boot
17.4 Implementing test specific configuration for Spring Boot
17.5 Introducing and testing a new feature into the Spring Boot application
17.6 Summary
Chapter 18: Testing a REST API
18.1 Introducing REST applications
18.2 Creating a RESTful API to manage one entity
18.3 Creating a RESTful API to manage two related entities
18.4 Testing the RESTful API managing two related entities
18.5 Summary
Chapter 19: Testing database applications
19.1 The Database Unit Testing Impedance Mismatch
19.1.1 Unit tests must exercise code in isolation
19.1.2 Unit tests must be easy to write and run
19.1.3 Unit tests must be fast to run
19.2 Testing a JDBC application
19.3 Testing a Spring JDBC application
19.4 Testing a Hibernate application
19.5 Testing a Spring Hibernate application
19.6 Comparing the approaches of testing database applications
19.7 Summary
Chapter 20: Test Driven Development with JUnit 5
20.1 Introducing Test Driven Development
20.2 Introducing the flights management application
20.3 Preparing the flights management application for TDD
20.4 Refactoring the flights management application
20.5 Introducing new features by working TDD
20.5.1 Adding a premium flight
20.5.2 Adding a passenger only once
20.6 Summary
Chapter 21: Behavior Driven Development with JUnit 5
21.1 Introducing Behavior Driven Development
21.1.1 Introducing a new feature
21.1.2 From requirements analysis to acceptance criteria
21.1.3 BDD benefits and challenges
21.2 Working BDD with Cucumber and JUnit 5
21.2.1 Introducing Cucumber
21.2.2 Moving a TDD feature to Cucumber
21.2.3 Adding a new feature with the help of Cucumber
21.3 Working BDD with JBehave and JUnit 5
21.3.1 Introducing JBehave
21.3.2 Moving a TDD feature to JBehave
21.3.3 Adding a new feature with the help of JBehave
21.4 Comparing Cucumber and JBehave
21.5 Summary
Chapter 22: Implementing a test pyramid strategy with JUnit 5
22.1 Software testing levels
22.2 Unit testing – our basic components work in isolation
22.3 Integration testing – units combined as a group
22.4 System testing – looking at the complete software
22.4.1 Testing with a mock external dependency
22.4.2 Testing with a partially implemented external dependency
22.4.3 Testing with the fully implemented external dependency
22.5 Acceptance testing – compliance with the business requirements
22.6 Summary

Polecaj historie