Implementation:AKSW RDFUnit TestUtils WriteTestsToFile
Appearance
| Knowledge Sources | |
|---|---|
| Domains | Semantic_Web, Test_Export, Serialization |
| Last Updated | 2026-10-16 00:00 GMT |
Overview
Concrete utility for serializing generated test cases to RDF files and generating unique test URIs.
Description
The TestUtils class provides static utility methods for test case serialization and URI generation:
- writeTestsToFile():*** Takes a collection of `GenericTestCase`, serializes each to RDF using `TestCaseWriter`, optionally adds explicit SPARQL WHERE clauses for pattern-based tests, and writes the model to an `RdfWriter` (file or stream).
- instantiateTestsFromModel():*** Reads test cases back from an RDF model using `BatchTestCaseReader`.
- generateTestURI():*** Creates a deterministic test case URI from the source prefix, pattern ID, bindings, and generator URI using an MD5 hash.
Usage
- Test generation export:*** Used to persist generated test cases to files for caching or inspection.
- Test case import:*** Used to load previously generated tests from RDF files.
- URI generation:*** Used internally by `TagRdfUnitTestGenerator` to create stable test URIs.
Code Reference
Source Location
- Repository: AKSW/RDFUnit
- File: rdfunit-core/src/main/java/org/aksw/rdfunit/utils/TestUtils.java
Signature
public final class TestUtils {
public static Collection<GenericTestCase> instantiateTestsFromModel(Model model);
public static Collection<GenericTestCase> instantiateTestsFromModel(Model model,
boolean strict);
public static void writeTestsToFile(Collection<GenericTestCase> tests,
RdfWriter testCache);
public static void writeTestsToFile(Collection<GenericTestCase> tests,
RdfWriter testCache, boolean addExplicitWhere);
public static String generateTestURI(String sourcePrefix, Pattern pattern,
Collection<Binding> bindings, String generatorURI);
}
Import
import org.aksw.rdfunit.utils.TestUtils;
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| tests | Collection<GenericTestCase> | Yes | Test cases to serialize |
| testCache | RdfWriter | Yes | Writer for output (file or stream) |
| addExplicitWhere | boolean | No | If true, add explicit SPARQL WHERE clause for pattern-based tests (default false) |
| model | Model | Yes (import) /// RDF model containing serialized test cases |
Outputs
| Name | Type | Description |
|---|---|---|
| writeTestsToFile() | void /// Writes test cases as RDF to the writer | |
| instantiateTestsFromModel() | Collection<GenericTestCase> | Deserialized test cases |
| generateTestURI() | String | Deterministic test URI with MD5 hash |
Usage Examples
Write Tests to File
import org.aksw.rdfunit.utils.TestUtils;
import org.aksw.rdfunit.io.writer.RdfFileWriter;
// Write generated tests to a Turtle file
RdfWriter writer = new RdfFileWriter("./tests/skos-tests.ttl", "TURTLE");
TestUtils.writeTestsToFile(generatedTests, writer);
Write with Explicit WHERE Clauses
// Include SPARQL WHERE clause in serialized output
TestUtils.writeTestsToFile(generatedTests, writer, true);
Load Tests from File
import org.apache.jena.rdf.model.ModelFactory;
import org.aksw.rdfunit.io.reader.RdfStreamReader;
// Read tests from RDF file
Model model = new RdfStreamReader("./tests/skos-tests.ttl", "TURTLE").read();
Collection<GenericTestCase> tests = TestUtils.instantiateTestsFromModel(model);
Related Pages
Implements Principle
Requires Environment
Uses Heuristics
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment