QNA > W > Quali Sono I Tre Vantaggi Dell'uso Del Cerotto?
Domanda

Quali sono i tre vantaggi dell'uso del cerotto?

Risposte
04/13/2022
Albarran

Most of the time when you patch something as part of a unit test, you will patch with a mock object anyway, so they work hand in hand.

To be honest I use Mock more often than patching -

  • I create mock objects (even mocks of builtin objects) in order to check what impacts and calls that the function under test makes on the object. Being able to track calls and provide known repeatable ‘fake data’ is really important. This includes mocking out individual files, or even mocking out entire file systems. Essentially when testing a function, you pass it mock objects in order to prove what happens to the object. A good example of using mocks is where you want to ensure that the file opens and closes a file correctly (even under error conditions) - you would pass a mocked file and then confirm that the file object had either close function called or that the function used __enter__() and __exit__() (context manager).
  • Patching is used when you know that the function under test uses some underlying library or code which is complex in it’s behaviour, and you want to have known repeatable results. For example you might be testing a function which your know uses the requests library to get data from a web site. You can use patching to replace the requests.get() function call with a known mock object, in order to make the requests.get() call to return known data, or generate an exception etc.
04/19/2022
Kasey Almodovar

A2A da Efrayim Bulka, Grazie.

Siccome sei un fanatico delle domande su Quora con oltre 7000 domande,

dovresti sapere ormai che molte domande incomplete non possono avere risposta.

Perciò perché hai postato solo metà della domanda?

Si tratta di un cerotto per una gomma di bicicletta forata, o di un cerotto per antidolorifici,

o della patch Kailo o di una patch per win 10?

Si prega di modificare la tua mezza domanda per trasformarla in una completa.

Dare una risposta
Cos'è l'OS patching in Linux. Come funziona? :: Come si può risolvere il glitch degli alberi di Cyberpunk 2077?
Link utili