I have 2 Java classes which have a symbiotic relationship.
Class 1 produces some output files and Class 2 consumes the output of class 1 and validates it. Both of these
Execute the main()
method of your class under test from within a JUnit method.
public class Class2 {
@Before
public void produceOutputFiles() {
Class1.main(new String[] { "these", "are", "commandline", "arguments"});
}
@Test
public void validateClass1Output() {
//read in the files and validate the output
}
}
Invoking Class1 via Process.exec()
is an option with many downsides. It is much simpler to keep both the test and the tested code within the same JVM.