title: JUnit Passing No arguments to main Method Java
body: <p>I'm trying to test my main method (which should accept exactly one argument) for no arguments passed. Can't seem to understand what am I missing here to achieve that.The nature of my program is such that it reads input from a file, creates objects by passing parameters read from the file, and displays output.</p>
  
  <blockquote>
    <p>Failure Message:</p>
    
    <p>org.junit.ComparisonFailure:   Expected :Please pass one argument</p>
    
    <p>Actual   :</p>
  </blockquote>
  
  <p>Here's my Unit Test:</p>
  
  <pre><code>    @Test
      public void givenNoParameter_shouldAskForOne() throws IOException {
      String[] args = {};
      String output;
  
      try (ByteArrayOutputStream bOutput = new ByteArrayOutputStream()) {
          System.setOut(new PrintStream(bOutput));
          Main.main(args);
          bOutput.flush();
          output = bOutput.toString();
      }
      String newLine = System.getProperty("line.separator");
      String[] breakDownOutput = output.split(newLine);
  
      assertEquals(1, breakDownOutput.length);
      assertEquals("Please pass one argument", breakDownOutput[0]);
  }
  </code></pre>
  
  <p>Main Method:</p>
  
  <pre><code>public static void main(String[] args) {
  
      if(args.length == 1) {
          DisplayOrder.setFilePath(args[0]);
          DisplayOrder.display();
      } else{
          System.err.println("Please pass one argument");
      }
  }
  </code></pre>
  
  <p>I've realized I was using System.err.println() in my main. Changing that to System.out.println() fixed it. </p>