Unit tests

Probably the most well-known type of test is the unit test. A lot of people call virtually any test they write to test their code a unit test, which is probably why this is such a well-known term for testing. Another reason for unit tests being so popular is that it's a very sensible test type.

A unit test is intended to make sure that an isolated object works as expected. This isolated object will usually be a class or struct, but it could just as well be a standalone method. It's important that unit tests do not rely on any other test or object. It's perfectly fine to set up an environment that has all the preconditions you need for your unit test, but none of this setup should be accidental. For instance, you shouldn't accidentally test other objects or depend on the order in which your tests are executed.

When you write a unit test, it's not uncommon to create instances of models that are stored in an array to represent a dummy database or fake REST APIs. Creating such a list of dummy data is done to ensure that a unit test does not fail due to external factors such as a network error. If your test should depend on certain external factors, you are probably writing an integration test.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset