I am writing tests, using testNG in this case, and I want to write my own assert method which uses some reflection to assert something is true. I intend to use the method all over in other helper methods.
There are checked exceptions that the test can throw, but shouldn't if done right. In all cases if the assert method throws an exception my desire is for it to propigate all the way to the top of the stack, causing the test to fail with a stack trace.
However, I would prefer not to have to add a throws method to every one of my test classes. Especially since there may be causes were other methods throw the same exception that I want eclipse to remind me to check for. Is there a way I can tell the testing framework itself that a specific exception being thrown should fail the test with a stack trace, as if I had thrown it through the entire stack?
I could use org.testing.Assert.fail, but that only allows me to provide a string instead of a full stack trace. I could wrap the checked exception in a runtime exception, but I feel that makes it (slightly) harder for testers to understand what actually happened. Is there a more direct way to say "fail here due to this exception"?
Aucun commentaire:
Enregistrer un commentaire