3 ms·
If I am honest, at this point I would rather not use a mock, but a stub / injection. I know this gets horrbily pedantic but its easier to see in code def diff
by lifeisstillgood 7y ago
If I am honest, at this point I would rather not use a mock, but a stub / injection.
I know this gets horrbily pedantic but its easier to see in code
def difficult_function(dbconn, a,b,c):
dbconn.execute(Select * from tbl)
<comlicated stuff invlvoing results set and a,b,c>
I would not want to mock the dbase at this point. Please can we instead do this
def difficult_function(dbconn, a,b,c):
resultset_as_dict = dbconn.execute(select * from tbl)
insider_function(a,b,c,results_set_as_dict)
def insider_function(a,b,c,results_set_as_dict):
This can now be tested without mocks quite easily.
I think if you are doing 'difficult' stuff with a exernal database you are de facto, writing integration tests.
In fact i would say anything involving a database MUST be treated as a integration test. If it takes ten minutes thats fine - its an integration test.
If you want fast and external connections, use sqllite as part of your testing CI suite. But dont moan.
and do not use Mocks.