Testing Features in Tecton
Testing is a crucial part of the feature development lifecycle. Tecton provides comprehensive testing tools that allow you to validate your features by using retrieval methods with mock data.
Core Testing Conceptโ
Testing in Tecton is fundamentally about using the same retrieval methods you'd use for training data, but with mock data instead of production sources. This approach ensures your features work correctly before deploying to production.
The key principle: Given your testing goal, you pick the appropriate testing method and use mock data to validate it.
Testing Goals and Methodsโ
Testing Goalsโ
When testing features, you typically want to validate one of the following:
- Final Feature Values - Test the complete feature computation including aggregations
- Partial Aggregates - Test intermediate aggregation results (for aggregate feature views)
- Feature View Transformation Only - Test just the transformation logic without aggregations
Retrieval Methodsโ
Your choice of testing method depends on what you want to retrieve:
- Time Range Retrieval - Get features valid over a time period
- Point in Time Retrieval - Get features for specific events/timestamps
- Online Retrieval - Get features for specific entities in real-time from the Feature Server
For detailed information about these retrieval methods, see Offline Retrieval Methods.
Testing Method Selection Matrixโ
| Testing Goal | Time Range Retrieval | Point in Time Retrieval | Online Retrieval |
|---|---|---|---|
| Final Feature Values | get_features_in_range() | get_features_for_events() | get_online_features() |
| Partial Aggregates | get_partial_aggregates() | N/A | N/A |
| Transformation Only | run_transformation() | N/A | N/A |
Since Realtime Feature Views are used for running transformations in real-time,
they do not support Time Range Retrieval but can still be tested using
run_transformation(), get_features_for_events() and get_online_features()
to test the transformation logic.
Method Detailsโ
get_features_in_range()- Returns features valid between start and end times, including aggregated valuesget_features_for_events()- Returns features for specific entity/timestamp pairs, useful for training data scenariosget_partial_aggregates()- Returns intermediate aggregation tiles for aggregate feature views (time range only)run_transformation()- Runs the Feature View transformation function as it would for a materialization job with the time range [start_time, end_time)get_online_features()- For Realtime Feature Views, runs the Feature View transformation in real-time and returns the results from the Transform Server. For other Feature Views that require materialization, this method simply returns the latest feature values from the online store.
Mock Data Usageโ
All testing methods support replacing the data sources with mock data, allowing you to:
- Control input data precisely for testing that covers your expected data patterns
- Test edge cases and specific scenarios
- Validate feature logic without relying on production data sources
Testing Workflowโ
- Identify your testing goal : Final values vs partial aggregates vs transformation only
- Choose your retrieval method : Time range vs point in time vs online
- Prepare mock data that represents your expected inputs
- Execute the test using the appropriate method
- Validate results against expected outputs
Testing by Feature Typeโ
Batch Featuresโ
Test batch features by mocking the batch data sources and validating:
- Transformation logic produces expected outputs
- Aggregations are configured to produce expected values
- Partial aggregates are generated as expected for aggregate feature views
- Feature values match expected results for known inputs
โ Testing Batch Features Guide
Stream Featuresโ
Test streaming features by mocking the stream data sources and validating:
- Stream transformations produce expected outputs
- Stream processing logic handles events as intended
- Features update appropriately with new data
โ Testing Stream Features Guide
Realtime Featuresโ
Test realtime features by mocking dependencies and validating:
- Request-time computations are correct
- Dependencies from batch/stream features are handled properly
- Feature logic produces expected outputs for various inputs
โ Testing Realtime Features Guide
Mocking Secrets and Resourcesโ
With Feature Views that depend on secrets or resources, you can define unit
tests that mock up the necessary input data, secrets and resources and assert
that you're getting the expected result. The MockContext class can be used to
mock any secrets or
resources that
are required by the Feature View.
### tests/transaction_amount_is_high.py ###
from tecton import MockContext, TestRepo
import pandas
# Testing the 'transaction_amount_is_high' feature which depends on request data ('amount') as input
def test_transaction_amount_is_high(repo_fixture: TestRepo):
transaction_amount_is_high = repo_fixture.get_feature_view("transaction_amount_is_high")
transaction_request = pandas.DataFrame({"amount": [124, 10001, 34235436234]})
# Use a MockContext to mock any secrets or resources
mock_context = MockContext(secrets={"my_secret": "my_secret_value"})
actual = transaction_amount_is_high.run_transformation(
input_data={
"transaction_request": transaction_request,
"context": mock_context,
},
).to_pandas()
expected = pandas.DataFrame({"transaction_amount_is_high": [0, 1, 1]})
pandas.testing.assert_frame_equal(actual, expected)
Beyond Feature Logic Testingโ
Integration Testingโ
Integration Tests simulate the materialization process for Feature Views to verify they will run successfully in production. These tests validate:
- Output schema matches your feature view definition
- Data source access, connectivity, and permissions
- Execution environment compatibility with your transformation code
For complete details, see Integration Tests.
Debugging Queriesโ
When issues arise with feature data quality, accuracy, or performance, you can debug the queries generated by feature retrieval methods by inspecting the query plan.
For details on debugging feature queries, see Debugging Queries.
Next Stepsโ
- Testing Batch Features - Comprehensive guide for batch feature testing
- Testing Stream Features - Stream feature testing methods and examples
- Testing Realtime Features - Realtime feature
testing including
get_features_for_eventswith mock dependencies - Unit Testing - Unit testing framework using
tecton testand best practices - Integration Tests - End-to-end materialization testing
- Debugging Queries - Query performance and accuracy debugging