Parameterized Test Cases

import org.junit.*;
import static org.junit.Assert.*;

public class AdditionTest {

  @Parameters public static int[][] data 
    = new int[][] {
       {0, 0, 0}, 
       {1, 1, 0}, 
       {2, 1, 1}, 
       {3, 2, 1}, 
       {4, 3, 1}, 
       {5, 5, 0}, 
       {6, 8, -2}
      };
		
  @Parameter(0) public int expected;
  @Parameter(1) public int input1; 
  @Parameter(2) public int input2; 
		
  @Test public void testAddition() {
    assertEquals(expected, add(input1, input2));
  }

  private int add(int m, int n) {
    return m+n;
  }
  
}

Is testAddition really a unit test any more?


Previous | Next | Top | Cafe con Leche

Copyright 2005 Elliotte Rusty Harold
elharo@metalab.unc.edu
Last Modified September 23. 2005