When joining a new project (and maybe even in a previously unknown programming language) we can get overwhelmed by the complexity of the test suites. Sometimes it can even be a nightmare to run them, not to mention understand what is going on. There are lots of levels the tests can be run on.
Let's start with the basics.
Anything that checks if a requirement is met is a test.
How do we apply this mindset in real life?
In software engineering, we want something that we can run and immediately see if what the project requires is what the solution provides.
Fortunately, we have the concept of an exit status
. Well behaved commands return such a status (sometimes called exit code
). A 0
means that the command finished successfully. A non-zero value is usually considered to be an error code
.
If a command utilizes this concept it is a perfect tool to use for testing.
We can print the exit status
on unix-like operating systems with echo $?
.
The simplest example is the test
command:
test -e a-non-existent-file.txt
echo $?
# returns: 1
test -e .
echo $?
# returns: 0
This is already a ready-to-use test. We can put it into a CI/CD pipeline which will fail if the README file is missing.
Top comments (0)