Validation Testing¶
Validation tests are data-driven instead of being specified explicitly. This document explains how to add a new validation test.
Adding a validation test¶
-
Create a new folder (not just a file!) in the
tests/resources/validation
directory or any subdirectory. Give the folder a descriptive name, since the folder name becomes part of the test name.Skipping a test
If you want to skip a test, add the prefix
skip-
to the folder name. -
Add files with the extension
.sdsdev
,.sds
, or.sdsstub
directly inside the folder. All files in a folder will be loaded into the same workspace, so they can reference each other. Files in different folders are loaded into different workspaces, so they cannot reference each other. - Add the Safe-DS code that you want to test to the files.
-
Specify the expected validation results using test comments (see below) and test markers (e.g.
fun »F«()
). The test comments are used to specify- the presence or absence of an issue,
- the severity of the issue, and
- the message of the issue.
The test markers are used to specify the location of the issue. Test comments and test markers are mapped to each other by their position in the file, i.e. the first test comment corresponds to the first test marker, the second test comment corresponds to the second test marker, etc. There may be more test comments than test markers, but not the other way around. Any additional test comments are applied to the entire file.
-
Run the tests. The test runner will automatically pick up the new test.
Format of test comments¶
- As usual, test comments are single-line comments that start with
$TEST$
. - Then, you specify whether the issue should be absent by writing
no
or present by writing nothing. - Next, you specify the severity of the issue by writing
error
,warning
,info
, orhint
. - Finally, you can optionally specify the message of the issue enclosed in double-quotes. You can also add an
r
before the opening double-quote to indicate that the expected message should be interpreted as a regular expression that must match the entire actual message.
Here are some examples:
We expect an error with the exact message Incompatible type.
.
We expect no warning with the exact message Name should be lowerCamelCase.
.
We expect an info with a message that matches the regular expression .*empty.*
.