[erlang-questions] Mocks and explicit contracts

José Valim jose.valim@REDACTED
Thu Nov 19 16:39:09 CET 2015


>
> The latter do work, though, IFF all concerned tests are just expecting the
> same thing from the called function... but most likely you have some tests
> that would check different scenarios. One test might check that the System
> Under Test behaves well if twitter does a positive response while another
> might check that the SUT  does  not fail in a catastrophic way if the
> twitter call gives garbage as response.
>

Yes. One solution to this problem is to parameterize the different
responses under the same system. For example, the username request for
"josevalim" would work but fail for "josevalim-fail". It is a very simple
solution but it can get unwieldy for complex systems where you need to test
many scenarios. In any case, I wouldn't discard this approach quickly, as
it fits simple problems quite well.

A more complex solution is to have an ownership pool where you could say:
"if this pid asks for this data, return this value". The benefit of such
system is that, if a pid has a given key reassigned without first
"deallocating" it, you certainly have a concurrency issue in your tests
where two tests need the same resource. We are building such system to
allow us to run tests concurrently even if they depend on a common external
resource like a database. We replace the regular database pool by the
ownership pool and run tests concurrently by wrapping each connection in a
transaction (works for SQL ones) or by running different database instances.


*José Valim*
www.plataformatec.com.br
Skype: jv.ptec
Founder and Director of R&D
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20151119/8b5a5ccf/attachment.htm>


More information about the erlang-questions mailing list