(+) Spy vs Mock
Last updated
Last updated
๊ตณ์ด ์กฐ์ ๋น์ฉ์ ์น๋ฅด๊ณ ํ ์คํธ๋ฅผ ์ํ ์กฐ์์ ํ๋ค๋ฉด Spy ๋ ํ์ฉํ๊ธฐ ์ข๋ค. Spy๋ ์ค์ ๊ฐ์ฒด์ ์ค์ ๋ฉ์๋ ํธ์ถ์ด ๋ฐ์๋๊ณ Mock ์ ๋ฆฌ์ผํ ๊ป๋ฐ๊ธฐ๋ค.
์ค ์ง๊ด์ ์ธ ์ค๋ช ์ ํด๋ ๊ฒ์ด ์์ด ์ฎ๊ฒจ์๋ค.
Technically speaking both "mocks" and "spies" are a special kind of "test doubles".
Mockito is unfortunately making the distinction weird.
A mock in mockito is a normal mock in other mocking frameworks (allows you to stub invocations; that is, return specific values out of method calls).
A spy in mockito is a partial mock in other mocking frameworks (part of the object will be mocked and part will use real method invocations).
mock ์ mock ์ด๊ณ , spy ๋ ๋ถ๋ถ์ ์ธ mock ์ด๋ค.
์๋ ์ํ ์ฝ๋๋ฅผ ๋ณด์. ๋ฌผ๋ก ์ ๋ถ ํต๊ณผํ๋ ์ฝ๋๋ค.
์๋ ์ฝ๋์์๋ ์ ์ ์๋ฏ์ด spy ๋ก ํ๋ฒ ๊ฐ์ผ mockList๊ฐ ์ค์ ๋ก add(100), add(200) ์ ํธ์ถ ํ์์ ์ ์ ์๋ค. ํ์ง๋ง Stubbing ์ญ์ ์ ๋์ํ๊ณ ์์์ ๋ณด์ฌ์ฃผ๊ณ ์๋ค.