TestForGit

package com.example.lenovo.textforgit;

/**
* Created by Lenovo on 2017/3/13.
*/

public class Calculator {
public double sum(double a, double b) {
return a+b;
}

public double substract(double a, double b) {
return a-b ;
}

public double divide(double a, double b) {
return a/b;
}

public double multiply(double a, double b) {
return a*b;
}
}

测试代码:
package com.example.lenovo.textforgit;

import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.*;

/**
* Created by Lenovo on 2017/3/13.
*/
public class CalculatorTest {
private Calculator mcalculator;
@Before
public void setUp() throws Exception {
mcalculator = new Calculator();

}

@Test
public void sum() throws Exception {
assertEquals(8d,mcalculator.sum(3d,5d),0);

}

@Test
public void substract() throws Exception {
assertEquals(1d,mcalculator.substract(5d,4d),0);

}

@Test
public void divide() throws Exception {
assertEquals(4d,mcalculator.divide(20d,5d),0);

}

@Test
public void multiply() throws Exception {
assertEquals(10d,mcalculator.multiply(2d,5d),0);

}

}
下面是测试运行结果

 




posted on 2017-03-16 23:45  宁夏请喝茶  阅读(107)  评论(0)    收藏  举报