When to do unit tests in Javascript?

Asked

Viewed 123 times

4

As far as it is advantageous to do unit testing in the presentation layer, and, what would be the scenarios where unit testing in Javascript is advantageous?

Only advantageous if you have calculations in Javascript?

Obs.: I’m gonna use Jasmine for the tests.

  • Doing tests is always a good practice, given that you do not how much a given system will evolve

1 answer

2

Starting from Software Engineering (but summarizing). Unit tests are derived from test cases, which in turn are based on use cases. You would need to have a documentation of your system with:

  • List of Requirements or basic guidelines of your system. Nothing to include animations, interfaces. They should only treat description of functionalities, being as simple as possible and not generic. Ex: The system must allow the user to change his credentials.

  • For each requirement, assemble one or more Casos de Usos, detailing how the user will use the system to perform the Requirement.

So for each use case, creates more than one test case, with inputs, expected outputs, and obtained outputs. Note that it is not possible to create a test case for interface as the interface is not a System Requirement.

This is because the interface is a surface layer of the system it totally depends on something that needs to be tested, so it ceases to be a test unitary true. In addition its interface could transmit wrong inputs to the next levels of the system, making it difficult to identify the outputs.

There are cases where you don’t have the system and it happens to be a completely front-end application, but even so it would be difficult and costly to discover all the possible test cases. I am not saying that it is not possible to test GUI, but that it would not be feasible, and it is not guaranteed of better maintainability of the system, because the test cases would be superficial.

  • I think it fits one or another test case example. For example, a function to represent as text a coordinate? Things that are data transformation independent of issues like the screen; the representation of the coordinate was just one of the first examples that came to mind. In this case, I believe that the test script (test case? There are people who use the terms with different meanings) would be the basic of this perhaps edition, with the example in [tag:Asmine] ending a response of great level

  • So what I wrote only what I know, I don’t know Joseph, I did with Professor of Software Engineering was very strict about it, it was only based on ISO rules of life.

  • For interface there is the discipline of Human-Machine Interface, which even so, the interface tests are aimed to facilitate the use, and not see if something is working. The Famous, if your grandmother can use it, then anyone can

  • makes sense to have unit tests to verify cases where the user does not fill, or fill incorrectly, fields of a form?

  • 1

    @Leila yes, this is the most expected case. The objective of the test is to bring rigidity to what the programmer expected.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.