Home / Companies / Convex / Blog / Post Details
Content Deep Dive

Running tests using a local open-source backend

Blog post from Convex

Post Details
Company
Date Published
Author
Sarah Shader
Word Count
1,587
Language
English
Hacker News Points
-
Summary

Convex provides a method for unit testing its functions using a locally running open-source backend, which is advantageous for verifying the behavior of applications such as a notes app. This setup involves running a local backend, deploying code, and executing queries and mutations through a testing framework, with the option to clear all test data between runs to maintain isolation. The process includes creating a script to manage the backend lifecycle and using testing helpers to ensure that functions only run in designated test environments. Despite offering a robust testing framework, there are limitations such as the inability to run scheduled functions or control randomness within tests. A practical example involves testing a notes app to ensure that users can only access their own notes, while more complex scenarios, like a chess app, demonstrate how to test authenticated functions. The article also contrasts using this method with the newer convex-test library for unit tests, highlighting the flexibility of Convex's backend platform for building scalable full-stack AI projects.