Introduction to tests in V
Writing tests in V is straightforward. In this section, we will explore three simple concepts that will get you started with writing tests in V. They are as follows:
- Use the
assert
keyword to compare the actual and expected outcome. - A file containing tests must end with the
_test.v
extension. - Each test is a function and must start with the prefix
test_
.
In the next subsection, we will learn the syntax of the assert
keyword and its usage in V.
The assert keyword
In V, you can use the assert
keyword to compare the outcome of a function you are writing tests for with the expected outcome. Following is the syntax that shows how to use the assert
keyword in V followed by a Boolean expression:
assert boolean_expression
In the preceding syntax, we can see that the assert
keyword is followed by an expression whose output must always evaluate to a Boolean result. If the Boolean result is true
then the assertion succeeds, otherwise...