Re: [HACKERS] Thoughts on unit testing?

Поиск
Список
Период
Сортировка
От Torsten Zuehlsdorff
Тема Re: [HACKERS] Thoughts on unit testing?
Дата
Msg-id be82716d-081c-8b6f-2a04-d22b4e8ae196@toco-domains.de
обсуждение исходный текст
Ответ на Re: [HACKERS] Thoughts on unit testing?  (Peter Geoghegan <pg@bowt.ie>)
Ответы Re: [HACKERS] Thoughts on unit testing?  (Chris Travers <chris.travers@adjust.com>)
Список pgsql-hackers

On 13.08.2017 21:19, Peter Geoghegan wrote:
> On Thu, Aug 10, 2017 at 2:53 PM, Thomas Munro
> <thomas.munro@enterprisedb.com> wrote:
>> The current regression tests, isolation tests and TAP tests are very
>> good (though I admit my experience with TAP is limited), but IMHO we
>> are lacking support for C-level unit testing.  Complicated, fiddly
>> things with many states, interactions, edge cases etc can be hard to
>> get full test coverage on from the outside.  Consider
>> src/backend/utils/mmgr/freepage.c as a case in point.
> 
> It is my understanding that much of the benefit of unit testing comes
> from maintainability. 

I never had this understanding. I write tests to test expected behavior 
and not the coded one. If possible i separate the persons writing 
unit-tests from the ones writing the function itself. Having someone 
really read the documentation or translate the expectation into a 
test-case, makes sure, the function itself works well.

Also it really safes time in the long run. Subtle changes / bugs can be 
caught which unit-tests. Also a simple bug-report can be translated into 
a unit-test make sure that the bugfix really works and that no 
regression will happen later. I literally saved ones a week of work with 
a single unit-test.

There are many other advantages, but to earn them the code need to be 
written to be testable. And this is often not the case. Most literature 
advises to Mocking, mixins or other techniques, which most times just 
translate into "this code is not written testable" or "the technique / 
language / concept / etc is not very good in being testable".

Greetings,
Torsten



В списке pgsql-hackers по дате отправления:

Предыдущее
От: Fabien COELHO
Дата:
Сообщение: Re: [HACKERS] proposal: psql command \graw
Следующее
От: Masahiko Sawada
Дата:
Сообщение: Re: [HACKERS] pgbench: Skipping the creating primary keys after initialization