views:

43

answers:

2

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!

+5  A: 

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.
Gishu
+3  A: 

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.

Marius
It would have been great if I could have selected both posts as the correct answer as they complement each other :(
devghost