For example, if I had the following class:
public class SomeClass{
public void someMethod() {
try {
//Some code, where comething could go wrong
} catch (Exception err) {
//Handling it amounts to logging the problem and trying to continue
}
}
}
If I then test this method with JUnit, then if something does go wrong in the try clause and the catch code is run, then the test will pass.
I want to make it so that the test will fail if the catch clause instructions are run.
I did think of a few ways I could try and write tests so that I get an equivalent sort of functionality, but there are reasons for each one that I do not want to approach it that way. It seems like trying to fail the test if any catch clause is reached is the cleanest way to do this, if that is in fact possible
Notes:
I know I could verify certain features of the code and check if they are a certain value/have been run a number of times with Mockito. However I want a solution where if changes were made to the test method that radically altered how it worked (but not what task was essentially being carried out) then I won't have to rewrite the test.
Unfortunately, just to make this proble more difficult, I am unable to make any modifictions to the source code. This position is out of my control so I have to work within these confines.
Aucun commentaire:
Enregistrer un commentaire