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

I am developing an application that relies mainly on an external dll, my application must support new versions of dll, and also be backward compatible with old ones.

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

Thanks!

+4
source share
2 answers

Write an adapter or facade that wraps the external DLL. Make it implement the IExternalDLL interface (of course, choose the best name), which documents / defines your needs from an external DLL; he does not need to accurately simulate function signatures of the actual implementation.

Write down a set of "contract tests" on the interface as you expect the interface to work.

Now you can write different adapters for each new version - in case of some changes with a change from v1 to v2. Your client is abstracted due to the interface. Its adapter / façade task is to ensure that the appropriate dll version matches the contract test. You write one test suite and run it with all adapter / facade implementations. Next time a new version comes out, you can

  • Use the latest adapter / façade if it suits your needs.
  • deploy a new one to fix any violations; make sure that you run it in accordance with the contract tests so that your client does not break with this adapter.
+5
source

If you use nant, a command assembly, or the like, you can copy the lib library to the folder in which your test project extracts its binaries before running the tests.

Pseudo example:

  • Copy the "old version" to the binary folder
  • Running tests (test task in the CI system)
  • Copy the "new version" to the binary folder
  • Run tests 5 ..

It is quite simple and should be easy to try. Note: “Responding to writing to an adapter or facade” is the preferred way to get your program to work with a different version, so I am also talking about actually testing several versions.

+3
source

Source: https://habr.com/ru/post/1309740/


All Articles