lundi 28 mars 2016

How to make unit test assertions in a unit testing framework agnostic manner

I'm presently working with a home spun unit testing helper package that is consumed by several internal projects. Up until recently this solution has been working well for us, and helps us follow the DRY principal for common testing helper methods. Unfortunately, this project is currently tied to nUniut, and we've just inherited some xUnit test projects that could benefit from this helper. This becomes a problem as each testing framework seems to manage assertions and watches for different thrown exceptions to indicate test failure.

I was hoping that it would simply be a matter of inheriting from a base exception class and most unit test frameworks would just catch and handle it as a failed (or passed) assertion appropriately. This however seems not to be the case.

Is there a proper way to Assert / throw Assertion exceptions without a direct unit test framework dependency that may can be consumed by the appropriate test runner? Or does a custom adapter have to be created for each unit test framework in order for my helper classes to be free from such a direct dependency of the test projects unit testing framework?

Aucun commentaire:

Enregistrer un commentaire