Commit 774ccf59 authored by Xiyang Lu's avatar Xiyang Lu

add Parameterized test

parent 65b21a26
import junit.framework.TestCase;
import org.junit.*;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import java.util.Arrays;
import java.util.Collection;
@RunWith(Parameterized.class)
public class CalculatorParamTest extends TestCase {
Calculator calculator;
int x;
int y;
int result;
@Before
public void init(){
this.calculator = new Calculator();
}
public CalculatorParamTest(int x, int y, int result) {
this.x = x;
this.y = y;
this.result = result;
}
@Parameterized.Parameters
public static Collection sums() {
return Arrays.asList(new Object[][] {
{ 1, 2, 3 },
{ 10, 5, 15 },
});
}
@Test
public void subTest2(){
Assert.assertEquals(result, calculator.add(x,y));
}
}
import org.junit.*;
public class CalculatorTest2 {
@Test
public void subTest1() throws InterruptedException {
int result = new Calculator().subtract(10,2);
Thread.sleep(1000);
Assert.assertTrue("Subtracting two numbers test case failed - 1", result == 8);
}
@Test
public void subTest2(){
int result = new Calculator().subtract(20,5);
Assert.assertTrue("Subtracting two numbers test case failed - 2", result == 15);
}
}
......@@ -2,7 +2,7 @@ import org.junit.runner.RunWith;
import org.junit.runners.Suite;
@RunWith(Suite.class)
@Suite.SuiteClasses({CalculatorTest.class, CalculatorTest2.class})
@Suite.SuiteClasses({CalculatorTest.class, CalculatorParamTest.class})
public class TestSuite {
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment