title: Junit parameterized tests using file input
body: <p>I have a query about using parameterized tests for my unit testing of my APIs. Now instead of building an arraylist like </p>
  
  <pre><code>Arrays.asList(new Object[]{
     {1},{2},{3}
  });
  </code></pre>
  
  <p>I want to read lines in the file one by one split them space and fill them in the array.
  This way everything would be generalized. Can anyone suggest me any such method with example?</p>
  
  <p>Also is there a way that I could be testing without declaring various arguments as the private members and initializing them in the constructor of the test unit?</p>
  
  <p>EDIT: Code as asked by Duncan</p>
  
  <pre><code>@RunWith(Parameterized.class)
  public class JunitTest2 {
  
      SqlSession session;
      Integer num;
      Boolean expectedResult;
      static BufferedInputStream buffer = null;
  
      public JunitTest2(Integer num, Boolean expected){
          this.num = num;
          this.expectedResult = expected;
      }
  
      @Before
      public void setup() throws IOException{
          session = SessionUtil.getSqlSessionFactory(0).openSession();
          SessionUtil.setSqlSession(session);
          buffer = new BufferedInputStream(getClass().getResourceAsStream("input.txt"));
          System.out.println("SETUP!");
      }
  
      @Test
      public void test() {
          assertEquals(expectedResult, num &gt; 0);
          System.out.println("TESTED!");
      }
  
      @Parameterized.Parameters
      public static Collection getNum() throws IOException{
          //I want my code to read input.txt line by line and feed the input in an arraylist so that it returns an equivalent of the code below
  
          return Arrays.asList(new Object[][]{
              {2, true},
              {3, true},
              {-1, false}
          });
      }
      @After
      public void tearDown() throws IOException{
          session.close();
          buffer.close();
          System.out.println("TEARDOWN!");
      }
  }
  </code></pre>
  
  <p>Also my input.txt will be as follows:</p>
  
  <pre><code>2 true
  3 true
  -1 false
  </code></pre>