Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Unit Test

GitDeveloperKim edited this page Jul 14, 2022 · 20 revisions

Test ์šฉ์–ด ์ •๋ฆฌ

  • link
  • smoke test : ๋ณธ๊ฒฉ์ ์ธ ํ…Œ์ŠคํŠธ ์ˆ˜ํ–‰์— ์•ž์„œ ๊ตฌ์ถ•๋œ ํ™˜๊ฒฝ์—์„œ ํ…Œ์ŠคํŠธ๊ฐ€ ๊ฐ€๋Šฅํ•œ์ง€ ํŒ๋‹จํ•˜๊ธฐ ์œ„ํ•œ ํ…Œ์ŠคํŠธ (๋นŒ๋“œํ…Œ์ŠคํŠธ)
  • sanity test : ์ž‘์€ ๋ณ€ํ™”๋“ค์ด ์ฝ”๋“œ๋‚˜ ๊ธฐ๋Šฅ์ƒ์— ์ด์Šˆ๋ฅผ ๋งŒ๋“ค์—ˆ๋Š”์ง€๋ฅผ ํ™•์ธํ•˜๊ธฐ ์œ„ํ•œ ํ…Œ์ŠคํŠธ
  • canary test : ์ƒˆ๋กœ ๊ฐœ๋ฐœํ•œ sw ๋ฒ„์ „์œผ๋กœ ๋ชจ๋“  ์‚ฌ์šฉ์ž๊ฐ€ ํ•œ๋ฒˆ์— ๋„˜์–ด์˜ค๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๋ผ ์ด์ „ ๋ฒ„์ „๊ณผ ํ˜ผ์šฉํ•ด์„œ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ์‹

unittest ๊ด€๋ จ document

unittest official doc
unittest official korean
unittest
unittest blog
coverage
coverage.py
unittest.mock
pytest doc
ํŒŒ์ด์ฌ ๋‹จ์œ„ ํ…Œ์ŠคํŠธ์— ๋Œ€ํ•œ ๊ฐœ๋… ๋ธ”๋กœ๊ทธ link
๋ชฉ์— ๋Œ€ํ•œ ๊ฐœ๋… ๋ธ”๋กœ๊ทธ link
mock ํŒจ์น˜์— ๋Œ€ํ•œ ๋ธ”๋กœ๊ทธ link

pip install

  • python -m pip install coverage

๋ช…๋ น์–ด

  1. ๋‹จ์œ„ํ…Œ์ŠคํŠธ
    python -m unittest -v TestCalculator.py
  2. ์ปค๋ฒ„๋ฆฌ์ง€
    coverage report
    coverage html
    coverage run --source=src --omit="./test/Test_" -m unittest discover .\test\Test.py

unittest

  • exception(divide by zero) ์‚ฌ์šฉํ•˜๊ธฐ : stackoverflow

mock

from unittest.mock import MagicMock

class testClass():
    def method(parameter_list):
        pass

test_class = testClass()
test_class.method = MagicMock(return_value=10)
test = test_class.method(1, 2, 3, key='value')
print(test)
Clone this wiki locally