Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to unit test my project against different versions of external dll api?

I am developing an app that relies heavily on an external dll, my app needs to support new versions of the dll as well as being backwards compatible with the old ones.

Are there any good ways to have my unit tests target all of these different dll versions without the need to rewrite the tests as soon as a new version of the api is released? How is this best handled?

Thanks!

like image 724
devghost Avatar asked Feb 28 '23 00:02

devghost


2 Answers

Write an Adapter or Facade that wraps the external DLL. Make it implement an interface IExternalDLL (of course choose a better name), which documents/specifies your needs from the external DLL ; it does not have to exactly mimic the function signatures of the actual implementation.

Write up a set of 'contract tests' against the interface, the way you expect the interface to work.

Now you can write different adapters per new version - in case of some breaking changes from v1 to v2. Your client is abstracted due to the interface.. Its the job of the adapter/facade to make sure the corresponding version of the dll meets the contract tests. You write one set of tests and exercise it with all implementations of the adapter/facade. The next time a new version is rolled out - you can

  • use the last adapter/facade if it meets your need
  • roll out a new one to fix any breaking changes ; ensure that you run it against the contract tests so that your client doesn't break with this adapter.
like image 178
Gishu Avatar answered Mar 01 '23 15:03

Gishu


If you are using nant, team build or similar you could xcopy the lib binary to the folder which your test project fetches its binaries from before running the tests.

Pseudo example:

  1. Copy "old version" to binary folder
  2. Run tests (test-task in CI-system)
  3. Copy "new version" to binary folder
  4. Run tests 5 ..

This is pretty simple and should be easy to try out. Note: "The write an adapter or facade" answer is the preferred way of making your program work against different version so do that too, I'm just talking about actually testing against multiple versions.

like image 40
Marius Avatar answered Mar 01 '23 14:03

Marius