Skip to main content
Version: Beta ๐Ÿšง

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:

  1. Final Feature Values - Test the complete feature computation including aggregations
  2. Partial Aggregates - Test intermediate aggregation results (for aggregate feature views)
  3. 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:

  1. Time Range Retrieval - Get features valid over a time period
  2. Point in Time Retrieval - Get features for specific events/timestamps
  3. 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 GoalTime Range RetrievalPoint in Time RetrievalOnline Retrieval
Final Feature Valuesget_features_in_range()get_features_for_events()get_online_features()
Partial Aggregatesget_partial_aggregates()N/AN/A
Transformation Onlyrun_transformation()N/AN/A
tip

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 values
  • get_features_for_events() - Returns features for specific entity/timestamp pairs, useful for training data scenarios
  • get_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โ€‹

  1. Identify your testing goal : Final values vs partial aggregates vs transformation only
  2. Choose your retrieval method : Time range vs point in time vs online
  3. Prepare mock data that represents your expected inputs
  4. Execute the test using the appropriate method
  5. 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โ€‹

Was this page helpful?