F
F
frontendo2017-09-22 17:52:00
JavaScript
frontendo, 2017-09-22 17:52:00

What is the optimal (time to write tests/efficiency) option for web api testing?

I'm going to implement a simple task manager on nodejs with the ability to assign executors.
As almost every project started with authentication, next there will be messages between users, editing a user profile, creating a project, adding members, creating tasks in a project, assigning executors and completing tasks.
Of course, I decided to write tests for my application to maintain best practice. For this case, I chose mocha + should + supertest, well, in principle, my question is not about that. I read, looked at testing and decided that unit testing would be too expensive in terms of time, but testing for specific URL requests with sending correct and incorrect data would be the best option.
For example, the first test I have is for registration. This is the data sent and all requests except the last one return errors:
[
{},
{email: 'tyrty'},
{email: 'tyrty"jskjk'},
{email: '[email protected]'},
{email: 'tyrty @jsk.jk'},
{email: '[email protected]', password: '123'},
{email: '[email protected]', password: '123".,sk'},
{email: '[email protected]', password: '1228uskj'},
{email: '[email protected]', password: '1228uskj', password_confirm: '123'},
{email: '[email protected]', password: '1228uskj', password_confirm: '1228uskj'},
I suspect this kind of testing is called functional testing. Since individual functions of the program are being tested.
But then, for example, there is an authentication test and there it turns out that I use the same [email protected] and password 1228uskj to test the correct request. And they write that it is necessary that the tests be independent of each other. And if they are independent, then where can I get the correct login and password (whether to climb into the database by some left method)?
Next, there will be more complex functionality for creating additional users, adding them to the project, assigning them roles with certain rights, and so on, that is, it will be necessary to check all sorts of options so that this action is not available to a user without the right to perform this or that action. That is, the test will go as if on the rise. At the end of the test or when it crashes, test information will be deleted from the database.
What is the best way to do it here?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ilya Gerasimov, 2017-09-22
@Omashu

Dynamically create the necessary environment for the test, see faker
You can write a couple of "helpers" for this business, as there are often a lot of manipulations with users in tests

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question