M
M
magary42017-02-07 00:33:21
Software testing
magary4, 2017-02-07 00:33:21

Unit testing example. More useful than assert(2,1+1 )?

the same primitive examples are everywhere
I can’t see any benefit
I don’t want to do tests for the sake of tests
I recently wrote a helper similar to

<th>{{ knp_pagination_sortable(pagination, 'Id') }}</th>

at first there were a couple of lines of code in it, then as it was used in the project, I saw cases when it was necessary to add more code to make it work,
i.e. as the project grew, cases that were not taken into account grew and I added them
before that - I just didn’t see these very ones cases
now to cover with tests for the sake of tests, I can’t force myself to
call this helper with various data, in fact assert(2,1+1 ) then assert(3,2+1) then assert(4,2+2)
for all these input data and under various conditions that I artificially come up with, it will be 99.9% green. my practice shows that the case when an error happens will most likely be detected by the customer with some of his non-trivial behavior
I see the point of doing this only when a couple of new cases are found to be implemented - then before that write tests so that they check all the previous logic in case the implementation of new cases breaks the old ones
for one I have one more question
besides the classic phpunit I am also trying now behat And that's what I really liked about it
When I eat <eat> cucumbers
  Then I should have <left> cucumbers

  Examples:
    | start | eat | left |
    |  12   |  5  |  7   |
    |  20   |  5  |  15  |

I write the function /* When I eat ARG cucumbers once
and then I can use it in hundreds of tests
how is it possible with phpunit ?
The second huge plus I noticed in behat (although it does not apply to unit testing) is that you can simply write "@javascript" and the test will be run through selenium. those. the second time you don't need to write the code, which saves a lot of time.
what problems can be with behat?
we are going to continue integration and there are rumors that it is harder with behat

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question