Book Image

Kotlin Blueprints

By : Ashish Belagali, Akshay Chordiya, Hardik Trivedi
Book Image

Kotlin Blueprints

By: Ashish Belagali, Akshay Chordiya, Hardik Trivedi

Overview of this book

Kotlin is a powerful language that has applications in a wide variety of fields. It is a concise, safe, interoperable, and tool-friendly language. The Android team has also announced first-class support for Kotlin, which is an added boost to the language. Kotlin’s growth is fueled through carefully designed business and technology benefits. The collection of projects demonstrates the versatility of the language and enables you to build standalone applications on your own. You’ll build comprehensive applications using the various features of Kotlin. Scale, performance, and high availability lie at the heart of the projects, and the lessons learned throughout this book. You’ll learn how to build a social media aggregator app that will help you efficiently track various feeds, develop a geospatial webservice with Kotlin and Spring Boot, build responsive web applications with Kotlin, build a REST API for a news feed reader, and build a server-side chat application with Kotlin. It also covers the various libraries and frameworks used in the projects. Through the course of building applications, you’ll not only get to grips with the various features of Kotlin, but you’ll also discover how to design and prototype professional-grade applications.
Table of Contents (16 chapters)
Title Page
Credits
About the Authors
Acknowledgments
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface

Testing


To test our Spring Boot application we need to test the URLs we are handling in our Controller, which means we need to write a test class for each Controller.  

Gradle dependency

We need to add the following dependencies to our build.gradle file for testing:

    // Testing
    testCompile group: 'junit', name: 'junit', version: '4.12'
    testCompile "org.springframework.boot:spring-boot-starter-test"

Test cases

All the tests are put in the test module with the same package name of the code. Mainly the test cases are written for the Controller, but you can even write for Repository for which you'll need to mock the database using Mockito or some other mocking library.

The MockMvc class is the entry point for performing server-side tests. We can perform HTTP requests such as GET, POST, and others on the URLs to test the REST endpoints.

MessageControllerTests: Test cases for the MessageController are written in human readable names using ` while writing function names.

Consider the following...