Principle:AKSW RDFUnit JUnit Validation Integration
| Knowledge Sources | |
|---|---|
| Domains | Testing, Semantic_Web, CI_CD |
| Last Updated | 2026-10-16 00:00 GMT |
Overview
Design pattern for integrating RDF data-quality validation into JUnit test suites using a custom JUnit Runner that auto-generates test cases from schemas and executes them as standard JUnit tests.
Description
JUnit Validation Integration bridges RDFUnit's validation framework with JUnit 4's test execution model. A custom `RdfUnitJunitRunner` extends JUnit's `ParentRunner` and transforms RDFUnit test cases into JUnit test descriptors. The integration uses annotations to configure validation:
- `@RunWith(RdfUnitJunitRunner.class)`: Activates the RDFUnit runner for the test class.
- `@Schema(uri=...)`: Specifies the schema ontology to validate against.
- `@TestInput`: Marks methods that return `RdfReader` instances providing the input data to validate.
- `@AdditionalData`: Marks an optional method returning extra RDF data to supplement the test input.
At initialization, the runner loads the schema, auto-generates test cases (using the same generation pipeline as CLI/API validation), and creates one JUnit test per (test case × test input method) combination. During execution, each test case runs as a SHACL Lite query against the test input, and failures are reported as standard JUnit assertion failures with violation details.
A key design decision is filtering: only violations where the failing node is actually part of the input model (not the schema) are reported as failures. This prevents false positives from schema-level annotations.
Usage
Use this principle when you want RDF validation to be part of your automated test suite and CI pipeline. It allows developers to define RDF quality checks declaratively and run them with standard JUnit tooling (Maven Surefire, Gradle, IDE test runners).
Theoretical Basis
The JUnit integration follows the custom Runner pattern:
# Abstract algorithm
class RdfUnitJunitRunner(ParentRunner):
def __init__(self, test_class):
schema_uri = test_class.get_annotation(Schema).uri()
schema_source = load_schema(schema_uri)
test_cases = generate_test_cases(schema_source) # auto-generation
test_inputs = test_class.get_methods_annotated_with(TestInput)
self.children = []
for test_input in test_inputs:
for test_case in test_cases:
self.children.append(
RdfUnitJunitTestCase(test_case, test_input, schema_source)
)
def run_child(self, test_case, notifier):
results = execute_shacl_lite(test_case, test_case.get_input_model())
violations = filter(results, lambda r: r.failing_node in input_model)
if violations:
notifier.fire_test_failure(violation_details)
else:
notifier.fire_test_finished()
Related Pages
Implemented By
- Implementation:AKSW_RDFUnit_RdfUnitJunitRunner
- Implementation:AKSW_RDFUnit_ShaclResultStatement_Evaluate