How to sequentially execute 2 Java classes via mvn command

后端 未结 1 1665
-上瘾入骨i
-上瘾入骨i 2021-01-25 22:10

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

1条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-25 22:12

    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.

    0 讨论(0)
提交回复
热议问题