1.待测试代码
package com.example.androietest;
public class Calculator {
public int add(int a ,int b){
return a+b;
}
public int multiplication(int a, int b){
return a*b;
}
}
2.测试代码
package com.example.androietest;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class CalculatorTest {
private Calculator mCalculator;
@Before
public void setUp() {
mCalculator = new Calculator();
}
@Test
public void testAdd(){
assertEquals(4, mCalculator.add(2,2));
}
@Test
public void testCheng(){
assertEquals(6, mCalculator.multiplication(2,3));
}
}
运行结果