Menu

Post image 1
Post image 2
1 / 2
0

The Mechanics Of Decision Of Test Double: Dummy

DEV Community·Azad Shukor·29 days ago
#44uxITCF
Reading 0:00
15s threshold

The most basic concept in test doubles is the dummy . When testing a function, there are usually two kinds of input: Meaningful input Data that affects the result of the function. Dummy input Data that is required by the function, but does not affect the behavior we are testing. Below is an example of meaningful data vs dummy data. This is a calculateShipping function: function calculateShipping ( weight : number , user : { id : string }, logger : { info : ( message : string ) => void } ) { return weight * 5 ; } Enter fullscreen mode Exit fullscreen mode In this function, only weight affects the result. The user and logger parameters are required, but they do not affect the shipping calculation. const meaningfulWeight = 10 ; const dummyUser = { id : " dummy-user " }; const dummyLogger = { info : () => {} }; const result = calculateShipping ( meaningfulWeight , dummyUser , dummyLogger ); expect ( result ).…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More