TopBraid Composer includes a capability to create and execute test cases that verify the correct definition of
SHACL shapes and functions.
In order to use this feature, create a new SHACL file containing .test.
in its file name.
The easiest way to do that is to use the File > New > RDF Test Cases File wizard.
Test files must import the DASH library, and may import other namespaces containing definitions you want to test.
TopBraid currently supports the following kinds of test cases:
ui:assert
statements.
Once the test cases have been defined, they can be executed at any time using the Test Cases View, which can be opened via
Window > Show View > Test Cases.
That view has a button to execute all tests, which will traverse all files containing .test.
in the whole workspace
and run any DASH test cases it finds in them.
Another button can be used to only execute the tests from the currently open file.
The output is a display of test failures and successes, and you can double-click on any row on the results table to navigate to the test case.
The easiest way to create a Function Test Case is to edit a test query in the SPARQL view.
For example, in order to test the correctness of a function ex:myFunction
, create a query such as
SELECT ?result WHERE { BIND (ex:myFunction(40, 2) AS ?result) }
and execute it in the SPARQL view to verify that the function behaves correctly.
Then, highlight a valid SPARQL expression with the cursor keys or the mouse, e.g. highlight
ex:myFunction(40, 2)
, and right-click on the SPARQL query to open the context menu.
In that menu, select Turn into dash:FunctionTestCase... and enter a valid local name of that test,
e.g. MyFunctionTest-001
.
This will create a test case that stores the value of ?result
as expected result.
You can later re-run those test cases to make sure that the function still fulfills its original contract.
The easiest way to create a Graph Validation Test Case is to run SHACL constraints via the SHACL Validation view:
Once you have completed these steps, the system will navigate to the newly created test case object.
That object will store the validation results in the property dash:expectedResult
.
Note that if the validation produced no results (i.e. everything was OK) then this property will also be empty.
There can only be one Graph Validation Test Case per test file.
This type of test cases is currently only supported for SPIN rules. The easiest way to create an Inferencing Test Case is to use TopBraid Composer:
Once you have completed these steps, the system will navigate to the newly created test case object.
That object will store the inferred triples as rdfs:Statement
instances in the property dash:expectedResult
.
Note that if the inferencing produced no results then this property will also be empty.
There can only be one Inferencing Test Case per test file.
This type of tests can be used to verify that a given SPARQL SELECT query still returns the same results as a "good" execution stored together with the test case. To create such a test case:
This type of tests is probably the most flexible option of all, as it allows you to execute almost any logic with SWP. To create an SWP test case:
ui:TestCases
ui:prototype
enter a snippet that you want to testui:assert
to define the test condition that you want to verify
SWP test cases pass if none of the ui:assert
elements report a failure.