tailieunhanh - Phát triển Javascript - part 5

Tham khảo tài liệu 'phát triển javascript - part 5', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | Test Functions Cases and Suites 13 Setup and Teardown xUnit frameworks usually provide setup and tearDown methods. These are called before and after each test method respectively and allow for centralized setup of test data also known as test fixtures. Let s add the date object as a test fixture using the setup method. Listing shows the augmented testCase function that checks if the test case has setup and tearDown and if so runs them at the appropriate times. Listing Implementing setup and tearDown in testCase function testCase name tests 0 var successful 0 var testCount 0 var hasSetup typeof function var hasTeardown typeof function for var test in tests if Atest .test test continue testCount try if hasSetup tests test output test 0c0 if hasTeardown If the tearDown method throws an error it is considered a test failure so we don t count success until all methods have run successfully successful catch e output test failed c00 Download from 14 Automated Testing var color successful testCount 0c0 c00 output strong testCount tests testCount - successful failures strong color Using the new setup method we can add an object property to hold the test fixture as shown in Listing Listing Using setup in the strftime test case testCase strftime test setup function new Date 2009 9 2 22 14 45 test format specifier Y function assert Y should return full year Y 2009 . Integration Tests Consider a car manufacturer assembly line. Unit testing corresponds to verifying each individual part of the car the steering wheel wheels electric windows and so on. Integration testing corresponds to verifying that the resulting car works as a whole or that smaller groups of units behave as expected . making sure the wheels turn when the steering wheel is rotated. Integration tests test the sum of its parts. Ideally those parts are unit .

TỪ KHÓA LIÊN QUAN