TopQuadrant/shacl

How do you suggest I'd do unit tests on corner cases to test individual SHACL contraints?

Closed this issue · 2 comments

Hi,

I'm looking to build a meta data ontology that allows for modelling data models. I'd like to use unit tests for the used SHACL constraints. Using this SHACL API I could build those tests. I'm curious if I'm missing something or is this the way to go?

KR,
Timon Schneider

Yes, you could create small data graphs that exercise the corner cases to verify the constraints that you expect will get reported. Basically compare the expected results with the actual results. We have formalized this pattern into a declarative vocabulary

http://datashapes.org/testcases.html#ValidationTestCase

which has an implementation in https://github.com/TopQuadrant/shacl/blob/master/src/main/java/org/topbraid/shacl/testcases/GraphValidationTestCaseType.java in case this helps, but you could just as well use your own JUnit test to make the comparison. The key line would be

if(expectedModel.getGraph().isIsomorphicWith(actualResults.getGraph()))

Okay, this is great. Thanks for you reply.