A
A
Anton Mashletov2017-11-01 15:12:40
Software testing
Anton Mashletov, 2017-11-01 15:12:40

A few simple testing questions. Who will help?

Sat down to write my first test (clap-clap). Please help me with a spherical example.
Let's say I have a website - a table of users, a form for creating / editing and viewing.
Entities: UserController resource controller, User model, index/create/edit/show views.
All this is ready and working.
That is, in theory, I need to make sure that:

  • main page opens
  • users are added
  • edited
  • viewed

I created a UserTest in the tests folder, added the first test, testIndex() , and I immediately had a bunch of questions:
  1. All these items can be done with $this->visit('/users') / see / dontSee / press.
    This, as I understand it, is functional testing. Will it be enough in this situation?
  2. index can still be tested by creating a new UserController and calling the index method with different filters (Request) and checking for errors. The same thing with the model, you can do: try save with different parameters, instead of filling out the form. Will this be a Unit Test? Is it necessary if there is item 1 or is it redundant?
  3. All tests: both unit and functional can be in the same UserTest file?
    Or do they need to be separated somehow and run according to their type? Should it be divided into something like UserControllerTest, UserModelTest, UserFuncTest?
  4. If I add a new user using visit, how can I roll back the changes or delete them?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Philipp, 2017-11-01
@mashletov

So, first you need to understand the difference between unit testing, integration testing, functional testing and regression testing.
Unit testing is for testing a particular method or class.
In your case, these will be tests for the model, for example, checking that the model creates an entry in the database with a certain structure.
Integration testing means checking how the components of the system work together. For example, checking that a controller method call creates an entry in the database with a certain structure. In this case, the integration of the controller with the model is checked. Higher-level integration testing can be done at the client level, where the service returns the desired object.
Functional testing verifies compliance with project requirements. For example, when you click the Delete button, a confirmation window appears with the text "Are you sure", then when you click the "Yes" button, the record is deleted from the database and the message "Record successfully deleted!" is displayed to the user.
A regression test is a repeated check of the work of a particular piece of code. As a rule, this is a section of code that has not been covered by tests before.
PHPUnit is originally designed for unit testing, but that doesn't stop you from using it for other kinds of testing. There are even connectors to WebDriver .
Testing controllers and models separately are unit tests.
Testing the controller-model link is integration testing.
Testing the entire site using the same Selenium, etc. This is functional testing.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question