manywaypark's Blog
개발, 검색, 함수

'unittest'에 해당되는 글 2건

  1. 2011.04.26 [tip] python unittest에서 exception 문제
  2. 2008.08.11 [TIP] erlang: unit, coverage test
문제:
python에서 unittest 모듈을 써서 unit test를 할 때 다음과 같이 썼다.

if __name__ == '__main__':
unittest.main()


수행하면 다음과 같이 테스트케이스 다 실행하고 OK 뜬 후에 exception이 났다. 좀 찜찜했다.

......
......
Ran 2 tests in 12.545s

OK
Exception in thread "main" Traceback (most recent call last):
  File "D:\comms_share\csm-gui-test\sikuli\csmLogin.sikuli\csmLogin.py", line 11
1, in <module>
    unittest.main()
  File "D:\comms_share\csm-gui-test\sikuli-script.jar\Lib\unittest.py", line 768
, in __init__
  File "D:\comms_share\csm-gui-test\sikuli-script.jar\Lib\unittest.py", line 806
, in runTests
SystemExit: False


해결:
여기저기 뒤져봤더니 IDLE 문제라고 이미 알려져있었다.
다음과 같이 쓰면 된다.

class FooTest(unittest.TestCase) :
def setUp(self) :
......
def tearDown(self):
......
def testSomething() :
......

if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(FooTest)  
unittest.TextTestRunner(verbosity=2).run(suite)


python 버전 정보는 다음과 같다

Python 2.6.5 (r265:79063, Jun 12 2010, 17:07:01)
[GCC 4.3.4 20090804 (release) 1] on cygwin


refs:
일단 eunit으로 테스트를 하는 것을 가정한다.

unit test - makefile에서...
make file에 다음과 같은 부분을 추가한 후에, make test 하면 간편하게 명령행에서 unit test를 수행할 수있다.
(makefile 뼈대는 Programming Erlang을 기초로 했다.)

......
MODS = doc str_util db i18n tiny_scan
......

test: compile test_subdirs
    rm -rf Mnesia.nonode@nohost # removes previous mneisa db (optional).
    @for m in ${MODS};\
    do \
        echo "testing $$m";\
        ${ERL} -noshell -pz "subdir1" -pz "subdir2" -s $$m test -s init stop;\
    done

test_subdirs:
    cd subdir1; make test
    cd subdir2; make test

unit test, coverage test - 개발중 REPL(distel 또는 erl prompt) 에서...
REPL을 사용해서 (멋지게) 코딩-테스트를 반복중이라면, 다음과 같은 모듈을 하나 디렉토리에 넣어서 test:unit() 또는 test:cover() 를 실행시켜서 unit test 및 coverage test를 시시때때로 수행해 볼 수 있다.


테스트는 아무리 강조해도 지나치지 않다.
경험상 대부분의 버그는 테스트되지 않거나, 적절하지 못한 테스트(셋)들을 통과한 코드에 기생한다.

happy hackin'



1 
분류 전체보기 (306)
잡담 (20)
함수형 언어 (65)
emacs (16)
java (18)
tips & tricks (154)
사랑 (1)
가사 (0)
독서 (4)
mobile (6)
비함수형 언어 (2)

공지사항

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백

04-27 09:12