Testing in Vapor 4

Use a pre-built Vapor application to learn both how to test your server-side Swift Vapor apps on macOS and also best practices to simplify your test code. By Tim Condon.

Leave a rating/review
Download materials
Save for later
Share
You are currently viewing page 3 of 3 of this article. Click here to view the first page.

Where to Go From Here?

You can download the completed project for this tutorial using the Download Materials button at the top or bottom of this tutorial.

In this tutorial, you learned how to test your Vapor applications to ensure they work correctly. Server-side Swift apps are typically deployed to Linux, and writing tests for your application means you can run these tests on Linux. This gives you confidence the application will work when you deploy it. Having a good test suite allows you to evolve and adapt your applications quickly. To learn about testing Vapor applications on Linux, see Server-Side Swift: Testing on Linux.

Vapor’s architecture has a heavy reliance on protocols. This, combined with Vapor’s dependency injection Service framework, makes testing simple and scalable. For large applications, you may even want to introduce a data abstraction layer so you aren’t testing with a real database.

This means you don’t have to connect to a database to test your main logic and will speed up the tests.

It’s important you run your tests regularly. Using a continuous integration (CI) system such as Jenkins or Bitbucket Pipelines allows you to test every commit. You must also keep your tests up to date.

Questions or comments on this tutorial? Leave them in the comments below!