Book Image

Spring Boot and Angular

By : Devlin Basilan Duldulao, Seiji Ralph Villafranca
Book Image

Spring Boot and Angular

By: Devlin Basilan Duldulao, Seiji Ralph Villafranca

Overview of this book

Angular makes building applications with the web easy and Spring Boot helps get an application up and running using just a few lines of code and minimal configuration. This book provides insights into building full-stack apps using Angular and Spring Boot effectively to reduce overall development time and increase efficiency. You'll start by setting up your CI/CD pipeline and then build your web application’s backend guided by best practices. You'll then see how Spring Boot allows you to build applications faster and more efficiently by letting the Spring Framework and Spring Boot extension do the heavy lifting. The book demonstrates how to use Spring Data JPA and add its dependencies along with Postgres dependencies in the project to save or persist a user's data in a database for future use. As you advance, you'll see how to write tests and test a service using Mockito. Finally, you'll create a CI workflow or pipeline for a Spring Boot and Angular application to enable operations to deliver quality applications faster. By the end of this Spring Boot and Angular book, you'll be able to build a full-stack web application and deploy it through continuous integration and continuous deployment.
Table of Contents (24 chapters)
Part 1: Overview of Spring Boot and Angular Development
Part 2: Backend Development
Part 3: Frontend Development
Part 4: Deployment

Writing tests in a service using Mockito

In the previous section, we created our unit tests using the H2 database; in this approach, we will completely omit the use of the database and utilize the concept of mocking in creating sample data in our unit tests. We will achieve this by using Mockito. Mockito is a mocking framework in Java that allows us to test classes in isolation; it does not require any databases.

It will enable us to return dummy data from a mocked object or service. Mockito is very useful, as this makes unit testing less complex, especially for larger applications, as we don’t want to test the services and dependencies simultaneously. The following are the other benefits of using Mockito:

  • Supports return values: Supports mocking return values.
  • Supports exceptions: Can handle exceptions in unit tests.
  • Supports annotation: Can create mocks using annotation.
  • Safe from refactoring: Renaming method names or changing the order of parameters...