Test main method without running the entire workflow

We are using a spring batch application with multiple steps, launched from a main() method. The following code mimics the working:

public class SomeBatchLauncher{          private static final String CONFIG = "application_context.xml";     private static final String JOB_NAME = "springJob";      public static void main(String args[]){        launch();         }      private static void launch(){          // Load application context using CONFIG           // Launch the batch job using JOB_NAME      } } 

With this setup, I need write test cases and ensure maximum coverage. Everything but the main method is covered. How do I ensure coverage of main() method without triggering the entire batch to be executed?

I’m thinking of creating a test spring configuration XML with dummy jobs and changing the CONFIG and JOB_NAME variables using reflection before calling the main() from my test class. Is this a sound approach?

Add Comment
0 Answer(s)

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.