I have two classes that I am testing (let them name ClassA and ClassB). Each of them has its own JUnit test class (testClassA and testClassB, respectively).
ClassA relies on ClassB to function properly, so I want to make sure that ClassB passes its tests before running testClassA (otherwise the results from testClassA would be meaningless).
What is the best way to do this? In this case, this is for assignment, so if possible, I need to save it in the two specified test classes.
Can / should I throw an exception from testClassA if the tests of TestClassB are not all passed? This would require that testClassB run invisibly and simply report its success / failure testClassA, and not in the GUI (via JUnit).
I am using Eclipse and JUnit 4.8.1
Update: so far the best I have managed is a separate file with a set of tests, as shown below. This is still not quite what I need, since it still allows you to run ClassB tests if ClassA does not perform some tests.
import org.junit.runner.RunWith; import org.junit.runners.Suite; @RunWith(Suite.class) @Suite.SuiteClasses({testClassA.class, testClassBCode.class}) public class testClassB { }
source share