Register to get access to 15+ free programming courses with interactive exercises

Introduction JS: Automated testing

Professional developers' code is less error-prone than that of beginners. This is not because they're keener, more quick-witted, or can see right through the code. The real reason is that they write tests.

Automated testing is an integral part of the programming process in professional environments. Tests are the only reliable way to make sure that code works. They don't get rid of bugs completely, but they do make sure you can keep their number at an acceptable level. The tests ensure that changes in one part of the system don't break other ones.

However, the tests are not there just to check how the code runs. There are other types of automated tests, such as performance tests or vulnerability tests.

Among the different types of automated tests, programmers are primarily concerned with functional tests. These tests verify that the code does what it needs to from the end user's point of view. For example, user registration should, as surprising as it may seem, register the user. And the tests should verify it.

Functional tests are usually divided into the following, depending on the degree of isolation of the tested parts of code:

  • Unit (modular) tests
  • Integration tests
  • System tests

The most straightforward and least effective tests are unit tests. They check the functionality of specific software modules, such as functions. These tests are the easiest to write, but they can't help make sure that the modules work together. That's what integration tests are for. Programmers should focus on these tests: they're still easy enough to write (if the project ecosystem prepared for it), and they cover a much larger part of the system.

The most complex and most effective are system tests. If it's a website, the testing is done through the browser. These tests emulate the behavior of a real user, moving around the site, clicking on links, and filling out and submitting forms. The difficulty with these tests is that they have to rely on the site's layout, which can change frequently and unpredictably. In addition, it's impossible to determine exactly when one action ended and another began in a browser (from the program's perspective). This is why such tests often break and are difficult to write and maintain.

Despite the differences, all automatic tests are based on the same principles. They often use the same tools. This course introduces the general testing principles and takes you through all the challenges that arise during testing step-by-step. The main subjects in this course are:

  • Asserts
  • Testing frameworks (Jest)
  • Unit testing
  • Matchers
  • Covering code with tests
  • Test-driven development (TDD)

Аватары экспертов Хекслета

Are there any more questions? Ask them in the Discussion section.

The Hexlet support team or other students will answer you.

For full access to the course you need a professional subscription.

A professional subscription will give you full access to all Hexlet courses, projects and lifetime access to the theory of lessons learned. You can cancel your subscription at any time.

Get access
130
courses
1000
exercises
2000+
hours of theory
3200
tests

Sign up

Programming courses for beginners and experienced developers. Start training for free

  • 130 courses, 2000+ hours of theory
  • 1000 practical tasks in a browser
  • 360 000 students
By sending this form, you agree to our Personal Policy and Service Conditions

Our graduates work in companies:

<span class="translation_missing" title="translation missing: en.web.courses.lessons.registration.bookmate">Bookmate</span>
<span class="translation_missing" title="translation missing: en.web.courses.lessons.registration.healthsamurai">Healthsamurai</span>
<span class="translation_missing" title="translation missing: en.web.courses.lessons.registration.dualboot">Dualboot</span>
<span class="translation_missing" title="translation missing: en.web.courses.lessons.registration.abbyy">Abbyy</span>
Suggested learning programs

From zero to a developer. Refunds in case you won't get a job

Frontend Developer icon
Profession
New
Development of front-end components for web applications
start anytime 10 months

Use Hexlet to the fullest extent!

  • Ask questions about the lesson
  • Test your knowledge in quizzes
  • Practice in your browser
  • Track your progress

Sign up or sign in

By sending this form, you agree to our Personal Policy and Service Conditions

Toto Image

Ask questions if you want to discuss a theory or an exercise. Hexlet Support Team and experienced community members can help find answers and solve a problem.