java参数化测试有2种方法

时间:2014-02-04 01:51:36

标签: java parameterized

您好我正在尝试对我的java代码使用参数化测试。我有两种我想测试的方法。一个将英里转换为公里,另一个将公里转换为英里。有没有办法测试参数化测试的两种方法,还是我必须为每种方法创建另一个参数化测试?

import static org.junit.Assert.*;

import java.util.Collection;
import java.util.InputMismatchException;
import java.util.Arrays;

import org.junit.Assert;
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 testLengthConverter {

private double lengths; 
private double expected; 


public testLengthConverter(double expected , double length){
  this.expected = expected; 
    this.lengths = length; 

}


 @Parameters
 public static  Collection<Object[]> lengthKm(){
return Arrays.asList( new Object[][]
        { {8.04672000307346, 5} , 
        {0.8046720003073461, .5},
        {3.10685596,5}, 
        {0.310685596, .5}});
}

 @Parameters
 public static  Collection<Object[]> lengthMile(){
return Arrays.asList( new Object[][]

        {});
 }

 @Test
 public void calcMile () 
 {
LengthConverter lengthMile= new LengthConverter();
assertEquals(expected,lengthMile.kmToMile(lengths),.0001);
 }

 @Test
 public void calcKm () 
 {
LengthConverter lengthKm= new LengthConverter();
assertEquals(expected,lengthKm.mileToKm(lengths), .0001);
        }

 }

0 个答案:

没有答案