Configure local testing

Testing your data project locally ensures that your resources are working as expected before you deploy your project to Tinybird.

There are several ways of generating test data for your local project. You can:

Fixture files

Fixtures are NDJSON files that contain sample data for your project. Fixtures are stored inside the fixtures folder in your project.

my-app/
├─ fixtures/
│  ├─ user_actions.json
│  └─ ...

Every time you run tb build, the CLI checks for fixture files and includes them in the build.

Generate mock data

The tb mock command creates fixtures based on your data sources. See tb mock for more information.

For example, the following command creates a fixture for the user_actions data source.

tb mock user_actions

» Creating fixture for user_actions...
✓ /fixtures/user_actions.ndjson created
...

You can use the --prompt flag to add more context to the data that is generated. For example:

tb mock user_actions --prompt "Create mock data for 23 users from the US"`

Call the Events API

Another way of testing your project is to call the local Events API endpoint using a generator, for example Mockingbird.

Obtain a token using tb token ls. Then, use the a command to send data to the local Events API endpoint:

# Install the Mockingbird CLI
npm install @tinybirdco/mockingbird-cli

# Call the Events API
TB_ENDPOINT=http://localhost mockingbird-cli tinybird
  --schema schema.json \
  --datasource "<your_data_source>" \
  --token "<your_token>" \
  --endpoint "custom" \
  --eps 50 \
  --limit 200

As you call the Events API, you can see errors and warnings in the console. Use this information to debug your datafiles.

Create a test suite

Once your project builds correctly, you can generate a test suite using tb test:

# Create a YAML test file inside /tests
tb test create user_action_insights_widget

Then, customize the tests to fit your needs.

You can use the --prompt flag to add more context to the data that is generated. For example:

tb test create user_action_insights_widget --prompt "test for the customer id 42 and the event type 'purchase'"

Next steps

Updated