=============
* calculator
#+begin_src java :classname Calculator :cmpflag "-cp ." :cmdline "-cp ."
public class Calculator{
public double add(double number1, double number2){
return number1+number2;
}
}
#+end_src
* parameterized test
#+begin_src java :classname ParameterizedTest :cmpflag "-cp ~/Linux/rep/junit-4.12.jar:~/Linux/rep/hamcrest-core-1.3.jar:." :cmdline "-cp ~/Linux/rep/junit-4.12.jar:~/Linux/rep/hamcrest-core-1.3.jar:."
import static org.junit.Assert.*;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import java.util.Arrays;
import java.util.Collection;
@RunWith(value=Parameterized.class)
public class ParameterizedTest{
private double expected;
private double valueOne;
private double valueTwo;
@Parameters
public static Collection<Integer[]> getTestParameters(){
return Arrays.asList(new Integer[][]{
{2, 1, 1},
{3, 2, 1},
{4, 3, 1},
});
}
public ParameterizedTest(double expected, double valueOne, double valueTwo){
this.expected = expected;
this.valueOne = valueOne;
this.valueTwo = valueTwo;
}
@Test
public void sum(){
Calculator calc = new Calculator();
assertEquals(expected, calc.add(valueOne, valueTwo), 0);
}
}
#+end_src
* run test
#+begin_src sh :results verbatim
java -cp .:/home/ahan/Linux/rep/junit-4.12.jar:/home/ahan/Linux/rep/hamcrest-core-1.3.jar: org.junit.runner.JUnitCore ParameterizedTest
#+end_src
#+RESULTS:
: JUnit version 4.12
: ...
: Time: 0.007
:
: OK (3 tests)
: