develog

JUnit Parameterized Test 본문

Dev/junit

JUnit Parameterized Test

냐옴 2012. 12. 2. 01:06

package test;


import static org.junit.Assert.*;


import java.util.Arrays;

import java.util.Collection;


import org.junit.Before;

import org.junit.Test;

import org.junit.runner.RunWith;

import org.junit.runners.Parameterized;

import org.junit.runners.Parameterized.Parameters;


@RunWith(Parameterized.class)

public class CalculatorTest {

Calculator cal;

private int num1;

private int num2;

public CalculatorTest(int num1, int num2) {

this.num1 = num1;

this.num2 = num2;

}

@Parameters

public static Collection<Object[]> data() {

Object[][] data = new Object[][] {

 {1, 2}

, {2, 3}

};

return Arrays.asList(data);

}

@Before

public void before() {

cal = new Calculator();

}


@Test

public void testSum() {

assertEquals(num1 + num2, cal.sum(num1, num2));

}


}


'Dev > junit' 카테고리의 다른 글

spring 2.5 에서는 junit 4.4 버전 사용  (0) 2012.12.05
JUnit 4 Test Suite  (0) 2012.12.02
JUnit4 hamcrest  (0) 2012.11.28
JUnit 4 Assert  (0) 2012.11.07
[junit] JUnit 4 Annotations  (0) 2012.11.07
Comments