Search code examples
phpunit-testingsymfonytestingfunctional-testing

Functional tests depth of assertions


I'm developing a project based on Symfony2 and PHPUnit. As far as I know functional tests represents what the system should do in a user perspective. But, I have some questions about this approach.

Suppose I'm testing an user registration form. So the first thing that I should to do after submit the form is to assert that the response was successful, an email was sent and probably make assertions on success page. Internally the system should store the registration date, change the user status and etc.

The question is: checking this low level of code like registration date and status should be covered by functional tests? If not, where is the best place to put this kind of tests?


Solution

  • if you are not forced to include it in integration tests then i recommend doing it as a unit tests. in general your tests structure should be a pyramid: http://martinfowler.com/bliki/TestPyramid.html

    i would divide this test into a few:

    • unit test(s) to check if the information is correctly deserialized in expected way and expected data structure is created
    • unit test(s) to check if that data structure is passed to specific services (e.g. if repository receives 'save' request with expected time and other paraemters)
    • integration test to check if repository correctly handles 'save' request. this is often a 'general' test, not tightly related to this specific user story.
    • general (not related to this specific user story) integration test to check if unit-tested infrastructure is connected correctly (including view/UI)

    this way you will get many unit tests and only a few integration/ui tests. and that's good. that's because maintaining functional tests requires a lot of effort and are very slow comparing to unit tests