Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Kotlin Blueprints

You're reading from   Kotlin Blueprints A practical guide to building industry-grade web, mobile, and desktop applications in Kotlin using frameworks such as Spring Boot and Node.js

Arrow left icon
Product type Paperback
Published in Dec 2017
Publisher Packt
ISBN-13 9781788390804
Length 260 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (3):
Arrow left icon
 Belagali Belagali
Author Profile Icon Belagali
Belagali
 Trivedi Trivedi
Author Profile Icon Trivedi
Trivedi
Akshay Chordiya Akshay Chordiya
Author Profile Icon Akshay Chordiya
Akshay Chordiya
Arrow right icon
View More author details
Toc

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...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime
Visually different images