lundi 25 mai 2015

Mocking Communications

I am building an application in python that uses a wrap to a library that performs hardware communication

I would like to create some test units and I am pretty new to unit tests, so I would like to mock the communications but I really don't know how to do it

quick example:

this is the application code using the comm lib

def changeValue(id, val):
    current_value = comm.getval(id)
    if (current_value != val):
        comm.send(id, val)

I want to test this without performing communications, i.e. replacing the comm.getval return by some mocked value, and sending comm.send to a mocked comm class.

Can anyone give a hint on that?

Aucun commentaire:

Enregistrer un commentaire