当前位置:编程学习 > JAVA >>

如何用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
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,