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


Our news feed application is ready, but it's not production ready until it is tested.

Adding Gradle dependency

We need to add JUnit and Ktor dependencies in the build.gradle file to test the application:

    // Testing
    testCompile group: 'junit', name: 'junit', version: '4.12'
    testCompile "io.ktor:ktor-server-test-host:$ktor_version"

Testing the application

We have three URL endpoints in our application, two of which return JSON data for which we will use an external tool named Postman to test them.

Testing the index URL

The preceding test case gets an instance of our application and sends a get request on the specified URL, which in this is /, aka an index URL, and it checks if the status is OK - 200 and content is Hello readers!:

    class ApplicationTest {
      @Test
      fun `check index page`() = withTestApplication(Application::main)  
      {
        with(handleRequest(HttpMethod.Get, "/")) {
          assertEquals(HttpStatusCode.OK, response.status())
          assertEquals...
lock icon The rest of the chapter is locked
Visually different images
CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
Kotlin Blueprints
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 $19.99/month. Cancel anytime
Modal Close icon
Modal Close icon