unit testing - Java Refactoring Strategy for Legacy Code -


i have been asked unit test legacy code.

currently, code tightly coupled 3rd party library both in terms of method calls , types used.

my first thought stub 3rd party library (using appropriate mocking framework) such can test code of interest rather 3rd party library. however, this, need refactor of code code of interest isolated external library dependency.

my initial thought extract interface , use wrapper make calls library. however, entirely decouple library need remove library specific types too, not method calls e.g.

libraryspecifictype[] myvar = wrappedlibrary.dox(); 

although have wrapped library call in above example, still returns library specific type, still coupled.

how around this? best strategy refactor code enable this?

thanks!

  1. i agree producing facade third party lib idea. talk facade , not 3rd party lib. place lib referred in facade.

  2. the issue libraryspecifictype bit more problematic. again wrap them help? not sure

  3. as testing. use mockito/powermockito. can tell return mock (of libraryspecifictype) mock of library , test way. having mock return mock sign of bad design in case points finger @ libraryspecifictype


Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -