DEV Community

Paweł Zaremba
Paweł Zaremba

Posted on • Originally published at tegh.net

1 1

What is a test in software development?

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.

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay