Saturday, 15 September 2012

JavaScript Unit Test. What to mock? -



JavaScript Unit Test. What to mock? -

i'm trying introduce unit test in development process , i'm not sure how it.

i have big application lot of modules ( separated js files ). example:

videoinfo.js availablevideos.js availablechannels.js networksettings.js .......

there few modules provide services rest:

eventhandler.js i18n.js ajax.js configuration.js auth.js basemodule.js ........

the question is: how test module videoinfo.js uses services modules? see 2 approaches:

i load videoinfo.js , mock internal interfaces. problem won't grab errors if of internal interfaces change. i load modules (the whole app) , test videoinfo real app environment ( except external ajax calls simulated)

what approach when have lot of internal dependencies?

ideally, want both of approaches in test suite.

you want mock of dependencies (in illustration videoinfo.js) can isolate code else , sure working correctly. depending on design of code have, can difficult. code may not have been written testing in mind , won't lend mocking.

you want have entire app level series of tests create sure interactions between parts work correctly. depending on app, these tests can brittle due dependence on info have no command over.

these tests in separate suites can run independently of each of other.

if getting started in writing tests code, write best test can. tests code , should refactored go along. write easiest test can. writing tests legacy code extremely difficult. current design may hard test properly. when making changes can.

javascript unit-testing qunit

No comments:

Post a Comment