Whenever I learn new programming language, I have been trying to learn its unit-test framework first. It is a quite useful. By writing learning test case from the very beginning of learning, you can easily learn how to test it with basic knowledge of your programming language. In most of cases, the code that easy to test is more easy to maintain. Well-made test cases can be a specification of user's requirements. It is more useful than well-made document. As application is going forward, it can be guard to protect legacy functionality.
1.Write test case
Jasmine test have a following structure. You can define test suite with "describe" method. It can have many test cases. Each of test case is defined by "it" method. The first argument of "it" method like [line 2], It is a description of test case. The second argument is a function which is called when this test case is executed. The expected result of logic or expected return value of function can be defined in "expect" method. With "toBe" method, you can call actual logic or function which you want to test. Not only "toBe", but Jasmine also provides many useful Matcher and API. You can find details in API documents2. Execute test case
Then, How can we execute test case? You need to download Jasmine from release page. There is a zip file. In there, you can find "SpecRunner.html". As see in [line 15], it includes source files which contains some logic. [line 18] includes test case file which contains test case to test logic or function in source files.If open "SpecRunner.html" with web browser, you can see the followings,
댓글 없음:
댓글 쓰기