java - jUnit Usage of setUp and tearDown -
this question has answer here:
being new junit have done far setting dependencies (i.e. creating objects) within test methods itself.
questions:
eclipse mocks unused variables, though.
setup,teardownfor?is practice create objects within
setup,nullthem out viateardown?what other use cases methods above?
what purpose of working pre-suite
setup,teardown. can give example when comes in handy?
cheers, andrew
being new junit have done far setting dependencies (i.e. creating objects) within test methods itself.
if initialized , cleaned correctly there nothing wrong approach. have way, if different tests need different dependencies.
eclipse mocks unused variables, though. setup , teardown for?
unused variables have nothing setup , teardown methods. should either use them or remove them.
is practice create objects within setup
in cases setup method (or nowadays @before annotation) necessary. constructor , inline initializes work well. @before annotation useful, if have inheritance in tests or want take advantage of @rules during initialization.
and null them out via teardown?
this bad idea. teardown (or nowadays @after annotation) should used clean external resources connections , files or revert changes made static state of application. there no need null fields garbage collector reclaim them anyway.
what purpose of working pre-suite setup , teardown. can give example when comes in handy?
sometimes want share resources between tests. example slow create database connections. suite methods let create them once per suite instead of once per test or per test class.
Comments
Post a Comment