title: how to test parameters using properties file in junit
body: <p>I was preparing a test case scenario where I put the values to be tested against their keys in <code>properties</code> file. I wanted if all key values satisfied with their corresponding values, the method should return true, else false. </p>
  
  <p>Below is my code:</p>
  
  <pre><code>package mypackTest;
  
  import java.io.File;
  import java.io.FileReader;
  import java.io.IOException;
  import java.util.Arrays;
  import java.util.Collection;
  import java.util.List;
  import java.util.Properties;
  import static org.hamcrest.CoreMatchers.is;
  import org.junit.BeforeClass;
  import org.junit.Test;
  import org.junit.runner.RunWith;
  import org.junit.runners.Parameterized;
  import org.junit.runners.Parameterized.Parameters;
  import static org.junit.Assert.assertThat;
  
  @RunWith(Parameterized.class)
  public class Test123 {
  
      static Properties p = null;
      private boolean expected;
  
      @Parameters
      public static List&lt;String[]&gt; data() 
      {
        String[][] data = new String[][] { { "D:\\personal\\config.properties" }};
     return Arrays.asList(data);
      }
  
  
      @BeforeClass
      public static void setup()
      {  
            p = new Properties();
          try 
          {
             //load a properties file 
              p.load(new FileReader(new File("D:\\personal\\config.properties")));
          } 
          catch (IOException ex) 
          {
         ex.printStackTrace();
          }
  }
  
  
  
      @Test
      public void do_test() {
  
          assertThat(TestThis.letstest(p.getProperty("abc1"), p.getProperty("abc2")), is(expected));
      }
  }
  </code></pre>
  
  <p><strong><em>the class that I wanted to test upon:</em></strong></p>
  
  <pre><code>package mypackTest;
  
  public class TestThis {
  
      public static boolean letstest(String abc1,String abc2){
          if(abc1.equals("xyz1")&amp;&amp; abc2.equals("xyz2")){
              return true;
          }
          return false;
      }
  }
  </code></pre>
  
  <p><strong><em>properties file</em></strong></p>
  
  <pre><code>abc1=xyz1
  abc2=xyz2
  </code></pre>
  
  <p><strong><em>TestRunner class</em></strong></p>
  
  <pre><code>package mypackTest;
  
  import java.util.Enumeration;
  
  import org.junit.runner.JUnitCore;
  import org.junit.runner.Result;
  import org.junit.runner.notification.Failure;
  
  import junit.framework.TestFailure;
  import junit.framework.TestResult;
  import junit.framework.TestSuite;
  
  public class TestRunner {
      public static void main(String[] args) {
  
                Result result = JUnitCore.runClasses(CalculatorTest.class);
  
                for (Failure failure : result.getFailures()) {
                   System.out.println(failure.toString());
                }
  
                System.out.println(result.wasSuccessful());
      }
  }
  </code></pre>
  
  <p>I am getting below output</p>
  
  <p><strong><em>OUTPUT</em></strong></p>
  
  <p>do_test0: wrong number of arguments</p>
  
  <p>false</p>