如何用JUnit测试add方法
--------------------编程问答-------------------- public class TestService extends BaseServiceTest{@InjectMocks
private AccountServiceImpl studentServiceImpl=new AccountServiceImpl();
/**
* 正常情况
*
*/
@Test
public void test1(){
Account account=new Account();
account.setBalance(400);
double addFee=2000;
double deductFee=100;
account=studentServiceImpl.addBalance(account,addFee);
account=studentServiceImpl.deductBalance(account, deductFee);
assertTrue(account.getBalance()==2300);
}
@Test
public void test2(){
Account account=new Account();
account.setBalance(400);
double addFee=2000;
double deductFee=3;
try {
account=studentServiceImpl.addBalance(account,addFee);
account=studentServiceImpl.deductBalance(account, deductFee);
} catch (Exception e) {
}
assertTrue(account.getBalance()==2400);
}
}
补充:Java , Java SE