-
Notifications
You must be signed in to change notification settings - Fork 36
Tests
Testing is a cornerstone of software development that ensures code quality, functionality, and robustness. Every contribution to the Raven codebase should include tests to validate the new code and its integration with the existing system.
The Raven Repository utilizes two main types of tests:
Unit tests are the first line of defense against bugs. They test individual pieces of code in isolation to ensure each part functions correctly.
Guidelines for Unit Tests:
- Write unit tests for every new functionality you add.
- Ensure your tests are focused, covering expected behavior, edge cases, and error conditions.
Integration tests verify that different parts of the application work together as expected.
Integration Test Workflow:
- The
test_raven.py
script runs the integration tests. - These tests scan the
RavenIntegrationTests
organization for workflows and composite actions and then index them. - The integration tests execute predefined queries focused on specific repositories. For each test, these queries retrieve a dictionary representation of nodes and relationships directly from the graph, corresponding to the particular aspects of the system under test.
- The output is then serialized into a JSON format and compared against a pre-existing snapshot—a JSON file representing the expected state of the graph based on this query's past results. This comparison helps ensure no unintended changes in the graph structure.
⚠️ WARNING: Update the snapshot JSON files whenever there are changes to the node structure in the Neo4j database to keep tests accurate.
To add an integration test, follow these steps:
- Index the necessary objects related to your new code.
- Utilize the
get_graph_structure
function fromtests\utils.py
with the appropriate queries to receive a complete structural dictionary. - Serialize this structure to a JSON file and validate that it matches the visual graph's appearance.
For example:
import json
from tests.utils import get_graph_structure
def test_repo_name() -> None:
"""
Tests Repo-name's graph structure.
"""
nodes_query = GET_NODES_BY_PATH_QUERY.format(paths_list=INTEGRAION_1_NODES_PATHS)
relationships_query = GET_RELATIONSHIPS_BY_PATH_QUERY.format(
paths_list=INTEGRAION_1_NODES_PATHS
)
graph_structure = get_graph_structure(nodes_query, relationships_query)
# Serialize and save the structure to a JSON file
with open('structures_json/repo-name.json', 'w') as file:
json.dump(graph_structure, file, indent=4)
# Compare the serialized structure to ensure accuracy