Acessing Junit Test results inside a test/Bestpractice?
I am currently writing a couple of tests for my system. Let's say i have function a and a function b that uses function a. I now want to implement it in a way, that if one of the tests for a fails the test b returns a message that it cannot work if a fails. My first question is, is this a good idea?
Secondly, so far i have been doing it like this:
Result result = JUnitCore.runClasses(TestA.class); if (!result.wasSuccessful()) fail("This test only works if a works")
But with this approach i can only check if a full class of tests works, not if a certain test works. How does one test check if another one failed? imagine they are both in the same class
This is generally not considered a best practice.
If your tests run quickly, then the simplest thing to do is just always run both tests. Doing what you have here just adds complexity.
In some cases, you can use Assume to cause a test to short circuit (without causing the test to fail) if a condition isn't true.