Test Cases

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:

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.

Function Test Cases

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.

Graph Validation Test Cases

The easiest way to create a Graph Validation Test Case is to run SHACL constraints via the SHACL Validation view:

  1. Populate the test file with shapes and example resources that either violate or match the shape definitions
  2. Use the green "run" button to Check all constraints
  3. Verify that the validation results are correct and that they match your expectations
  4. When satisfied, click the Turn into Test Case button

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.

Inferencing Test Cases

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:

  1. Create a test file that imports the rules and data graphs that you want to test
  2. Run inferences with the default settings, i.e. multiple iterations.
  3. Verify that the inferences are correct and that they match your expectations
  4. When satisfied, select Turn into Test Case from the drop down menu of the Inferences View

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.

Query Test Cases

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:

  1. Create a test file that imports the data you want to query
  2. Write and run a SPARQL SELECT query in the SPARQL View. This must contain an ORDER BY clause.
  3. Verify that the results match your expectations
  4. When satisfied, select Turn into Test Case from the drop down menu of the SPARQL View

SWP Test Cases

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:

  1. Create a test file that imports an SWP library such as its HTML namespace, plus possibly others
  2. Create a subclass of ui:TestCases
  3. In the ui:prototype enter a snippet that you want to test
  4. Use ui: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.