http://cxxtest.sourceforge.net
C++ ์ ๊ฒฝ์ฐ๋ ์ธ์ด์ฐจ์์์์ ๋ฆฌํ๋์ ์ ์ง์ํ์ง ์๊ธฐ ๋๋ฌธ์ ํ ์คํธ๋ฅผ ์ถ๊ฐํ๋ ๋ถ๋ถ์ด ์๋ฐ๋ ํ์ด์ฌ ๋ฑ์ ๋นํด ์๋นํ ๊ท์ฐฎ๋ค. ๊ทธ์ ๋ํ ๋์์ผ๋ก CUT ๋ฑ์ C UnitTestFramework ์ ๊ฒฝ์ฐ ์ธ๋ถ์์ Perl ๋ฑ์ผ๋ก ์์ฑํ ์คํฌ๋ฆฝํธ์ธ์ด๋ก ํ ์คํธ์คํ๊ณผ ๊ด๋ จํ Runner ๋ฅผ ์ฝ๋์ ๋๋ ์ดํ ํ๋ ๋ฐฉ๋ฒ์ ์ฐ๊ณ ์๋ค.
C++ ์ ๊ฒฝ์ฐ๋ ์ธ์ด์ฐจ์์์์ ๋ฆฌํ๋์ ์ ์ง์ํ์ง ์๊ธฐ ๋๋ฌธ์ ํ ์คํธ๋ฅผ ์ถ๊ฐํ๋ ๋ถ๋ถ์ด ์๋ฐ๋ ํ์ด์ฌ ๋ฑ์ ๋นํด ์๋นํ ๊ท์ฐฎ๋ค. ๊ทธ์ ๋ํ ๋์์ผ๋ก CUT ๋ฑ์ C UnitTestFramework ์ ๊ฒฝ์ฐ ์ธ๋ถ์์ Perl ๋ฑ์ผ๋ก ์์ฑํ ์คํฌ๋ฆฝํธ์ธ์ด๋ก ํ ์คํธ์คํ๊ณผ ๊ด๋ จํ Runner ๋ฅผ ์ฝ๋์ ๋๋ ์ดํ ํ๋ ๋ฐฉ๋ฒ์ ์ฐ๊ณ ์๋ค.
CxxUnit์ CUT์ C++๋ฒ์ ์ด๋ผ ๋ด๋ ์ฝ๊ฐ ์ํตํ๋ฆฌ๋ผ ๋ณธ๋ค.(์ค๋๋๊ธฐ๋ CxxUnit ์ด ๋ ์ค๋๋์๋๊ฑธ๋ก ๊ธฐ์ต) Python ์ด๋ Perl ์ ์ฝ๋์ ๋๋ ์ดํฐ ์คํฌ๋ฆฝํธ๋ฅผ ์ด์ฉ, Runnerํ์ผ์ ๋ง๋ค์ด์ค๋ค. ์ด๋ฅผ ์ปดํ์ผํ์ฌ ์คํํ๋ฉด ํ
์คํธ๊ฐ ์คํ๋๋ค.
1002์ ๊ฒฝ์ฐ ์์ CxxUnit ์ ์ฌ์ฉ์ค. ๋ฐ์ ์คํฌ๋ฆฝํธ๋ฅผ Visual Studio ์ Tools(์ผ์ข
์ External Tools)์ ์ฐ๊ฒฐ์์ผ๋๊ณ ์ด๋ค. Tool ์ ์คํํ์ฌ ์ฝ๋์ ๋๋ ์ดํ
ํ๋ค, ์ปดํ์ผ. (cxxtestgen.py ๋ CxxTest ์์ ์๋ค.) ํ์ผ ์ด๋ฆ์ด Test ๋ก ๋๋๋ ํ์ผ๋ค์ ๋ฑ๋กํด์ค๋ค.
~cpp from os import * from os.path import * def toStr(aList): return ' '.join(aList) def main(): testFiles = [] for eachFile in listdir("."): if isfile(eachFile): lastestPeriod = eachFile.rfind(".") fileName = eachFile[:lastestPeriod] extension = eachFile[lastestPeriod+1:] if fileName.endswith("Test"): print fileName, extension testFiles.append(eachFile) '''cmd= "python cxxtestgen.py --runner=ParenPrinter --gui=Win32Gui -o runner.cpp "+toStr(testFiles)''' cmd= "python cxxtestgen.py --runner=ParenPrinter -o runner.cpp "+toStr(testFiles) print cmd system(cmd) if __name__=="__main__": main()
๋จ์ ์ด ์๋ค๋ฉด ํ
์คํธ ์์์ด ์๋๋ค๋ ์ ์ด๋ค. ๊ฐ์ธ์ ์ผ๋ก MockObject ๋ง๋ค์ด ์ธํฐํ์ด์ค ํ
์คํธ ๋ง๋ ๋ค RealObject ๋ฅผ ๋ง๋ค์ด ํ
์คํธํ๋ ๊ฒฝ์ฐ๊ฐ ๋ง์ ๋งํผ ๊ท์ฐฎ๋ค. (ํ
์คํธ์ ์ค๋ณต์ผ๋ก ์ด์ด์ง๋ฏ๋ก) ์ดํ.