I would like to find unit tests (written with JUnit) which never fail. I.e. tests which have something like
try {
// call some methods, but no assertions
} catch(Throwable e) {
// do nothing
}
Those tests are basically useless, because they will never find a problem in the code. So is there a way to make each (valid) unit test fail? For instance each call to any assert method would throw an exception? Then tests which still remain green are useless.
Well, one approach is to use something like Jester which implements mutation testing. It doesn’t do things quite the way you’ve suggested, but it tries to find tests which will still pass however much you change the production code, but randomly mutating it and rerunning the tests.