Suite runner

套件运行器
它可以运行多个测试。
package test;

public class Calculator {
public double add(double number1, double number2) {
return number1 + number2;
}
}


package test;

import org.junit.Assert;
import org.junit.Test;

public class CalculatorTest {
@Test
public void a() throws Exception {
Calculator c = new Calculator();
double result = c.add(0, 1);

Assert.assertEquals("结果不正确", result,1, 0);
}

@Test
public void a1() throws Exception {
Calculator c = new Calculator();
double result = c.add(1, 2);

Assert.assertEquals("结果不正确", result,3, 0);
}
}


package test;

import org.junit.Assert;
import org.junit.Test;

public class B {
@Test
public void b() throws Exception {
Calculator c = new Calculator();
double result = c.add(1, 1);

Assert.assertEquals("结果不正确", result, 2, 0);
}
}

package test;

import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;

@RunWith(value = Suite.class)
@SuiteClasses(value = { CalculatorTest.class, B.class })
public class A1 {

}

这里有两个测试类,以及一个设置为了套件运行器的测试类。
运行A1,会讲两个测试都运行了。

另外测试套件可以去调用测试套件。
增加我们的测试


package test;

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

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;

@RunWith(value = Parameterized.class)
public class ParameterTest {
private double expected;
private double valueOne;
private double valueTwo;

public ParameterTest(double expected, double valueOne, double valueTwo) {
this.expected = expected;
this.valueOne = valueOne;
this.valueTwo = valueTwo;
}

@Parameters
public static Collection<Integer[]> getTestParameters() {
return Arrays.asList(new Integer[][] { { 2, 1, 1 }, // expected,
// valueOne,
// valueTwo
{ 3, 2, 1 }, // expected, valueOne, valueTwo
{ 4, 3, 1 }, // expected, valueOne, valueTwo
});
}

@Test
public void sum() {
Calculator calc = new Calculator();
Assert.assertEquals(expected, calc.add(valueOne, valueTwo), 0);
}
}


package test;

import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;

@RunWith(value = Suite.class)
@SuiteClasses(value = { ParameterTest.class })
public class A2 {

}


package test;

import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;

@RunWith(value = Suite.class)
@SuiteClasses(value = { A1.class, A2.class })
public class AllTest {

}

在AllTest 设置的SuiteClasses里面的类本身就是测试套件。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值