๐์๋ก
์ด๋ฒ ๊ธ์ ์ผ๊ณฐ ์์นด๋ฐ๋ฏธ์ ํ ๊ฐ์๋ฅผ ๊ฑฐ์ ๋ฐ๋ผ์ผ๋ค์ํผ.. ๋ค.. ๊ทธ๋ ์ต๋๋ค..
์ดํดํ๋ฉด์ ์ฐ๊ณ ์์ด์ ใ ใ ,,
์ด ํํธ๋ Test file์ ๋ณด๋ฉฐ ๋ง๋ฌด๋ฆฌ ์ง์ต๋๋ค.
XCTest
XCTest๋ ์ ๋ ํ ์คํธ, ํผํฌ๋จผ์ค ํ ์คํธ, UI ํ ์คํธ๋ฅผ ๋ง๋ค๊ณ ์คํํ๋ ํ๋ ์ ์ํฌ์ด๋ค.
XCTestCase
ํ ์คํธ ํด๋์ค๊ฐ ์์ํ๊ณ ์๋ XCTestCase๋ ๋ฌด์์ผ๊น?
XCTestCase ๋ ์ถ์ ํด๋์ค์ธ XCTest์ ํ์ ํด๋์ค๋ก, ํ ์คํธ๋ฅผ ์์ฑํ๊ธฐ ์ํด ์์กํด์ผ ํ๋ ๊ฐ์ฅ ๊ธฐ๋ณธ์ ์ธ ํด๋์ค์ด๋ค.
XCTest๋ ํ ์คํธ๋ฅผ ์ํ ํ๋ ์ ์ํฌ์ ์ด๋ฆ์ด๊ธฐ๋ ํ๊ณ , ํ ์คํธ์์ ๊ฐ์ฅ ๊ธฐ๋ณธ์ด ๋๋ ์ถ์ ํด๋์ค์ ์ด๋ฆ์ด๊ธฐ๋ ํ๋ค.
XCTestCase๋ฅผ ์์๋ฐ์ ํด๋์ค์์๋ test์์ ์ฌ์ฉ๋๋ ๋ค์ํ ํ๋กํผํฐ์ ๋ฉ์๋๋ฅผ ์ฌ์ฉํ ์ ์๋ค.
setUpWithError()
setUpWithError()๋ ๊ฐ๊ฐ์ test case ๊ฐ ์คํ๋๊ธฐ ์ ๋ง๋ค ํธ์ถ๋์ด ๊ฐ ํ ์คํธ๊ฐ ๋ชจ๋๊ฐ์ ์ํ์ ์กฐ๊ฑด์์ ์คํ๋ ์ ์๋๋ก ๋ง๋ค์ด ์ค ์ ์๋ ๋ฉ์๋์ด๋ค.
tearDownWithError()
tearDownWithError()๋ ๊ฐ๊ฐ์ test ์คํ์ด ๋๋ ํ ๋ง๋ค ํธ์ถ๋๋ ๋ฉ์๋์ด๋ค. ๋ณดํต setUpWithError()์์ ์ค์ ํ ๊ฐ๋ค์ ํด์ ํ ๋ ์ฌ์ฉ๋๋ค.
ํธ์ถ ์์
setUpWithError()
TestCase 1
tearDownWithError()
setUpWithError()
TestCase 2
tearDownWithError()
setUpWithError()
TestCase 3
...
setUp() ๊ณผ tearDown() ๋ฉ์๋ ์ฐจ์ด
setUp() ๊ณผ tearDown() ๋ฉ์๋์ setUpWithError(), tearDownWithError()์ ์ฐจ์ด๋ ์๋ฌ๋ฅผ throw ํ ์ ์๋๋์ ๋ํ ์ฐจ์ด์ด๋ค. ํ ์คํธ ๋ฉ์๋๋ฅผ throw ๋ฉ์๋๋ก ๋ง๋ค์ด์ฃผ๋ฉด, ๋ด๋ถ์์ ๋ฐ๋ก ์๋ฌ ํธ๋ค๋ง์ ํด์ฃผ๋ ์์ ์์ด ํ ์คํธ๋ฅผ ์์ฑํ ์ ์๋ค๋ ์ด์ ์ด ์๋ค. ์๋๋ setUp()๊ณผ tearDown() ๋ฉ์๋๊ฐ ๊ธฐ๋ณธ ๋ฉ์๋๋ก ์ ๊ณต์ด ๋์๋๋ฐ xcode 11.4 ๋ฒ์ ์ดํ๋ก ๊ธฐ๋ณธ์ผ๋ก setUpWithError(), tearDownWithError()๋ฅผ ์ ๊ณตํ๊ณ ์์ด์.
์์ธํ ๋ด์ฉ์
Apple Developer Documentation
developer.apple.com
testExample()
test๋ก ์์ํ๋ ๋ฉ์๋๋ ์ฐ๋ฆฌ๊ฐ ์์ฑํด์ผํ test case ๊ฐ ๋๋ ๋ฉ์๋์ ๋๋ค. ์ฐ๋ฆฌ๊ฐ ํ ์คํธํ ๋ด์ฉ์ ๋ฉ์๋๋ก ์์ฑํด๋ณผ ์ ์์ต๋๋ค. ๋ฉ์๋ ๋ค์ด๋ฐ์ ์์์ ๋ฌด์กฐ๊ฑด test๋ก ์์๋์ด์ผ ํ๋ค.
๐๐ป Ref
Unit Test ์์ฑํ๊ธฐ - ์ผ๊ณฐ๋ท๋ท
Unit Test ์์ฑํ๊ธฐ ํ ์คํธ๋ฅผ ์์ฑํ๋ฉด ์ข๋ค๋ ๋ง์ ๋ง์ด ๋ค์ด๋ณด์ จ์ ๊ฒ ๊ฐ์ต๋๋ค. ํ์ง๋ง ๋ง์ ํ ์คํธ๋ฅผ ์์ฑํด๋ณด๋ ค๊ณ […]
yagom.net