EasyMock是一个用于Java开发的开源框架,用于模拟方法调用和测试代码中的依赖关系。它可以帮助开发人员在单元测试中模拟对象的行为,以便更容易地进行测试。
EasyMock的主要特点包括:
EasyMock的应用场景包括:
腾讯云提供了一些与EasyMock类似的产品和服务,例如:
请注意,以上提到的腾讯云产品仅作为示例,不代表推荐或要求使用。在实际使用中,您可以根据具体需求选择合适的产品和服务。
import org.easymock.EasyMock;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.easymock.PowerMock;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.springframework.aop.framework.Advised;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.util.ReflectionTestUtils;
@RunWith(PowerMockRunner.class)
@PrepareForTest( { PaymentReconService.class })
@PowerMockIgnore(“org.apache.log4j.*”)
public class PaymentGatherServiceTest extends PaymentServiceTestBase {
@Autowired
private GatherService gatherResultService;
@Autowired
private PaymentBaseDAO baseDAO;
/**
* 测试正常postback
*/
public void testPaymentSucc() {
PaymentReconService mock = mock();
Long pbId = 10004L;
String pbStatus = PaymentBaseEO.PB_STATUS_GATHER_SUCC;
BigDecimal succAmount = new BigDecimal(“99.3”);
try {
GatherOrderRO ro = gatherResultService.processPaymentGather(pbId, pbStatus, succAmount, succAmount);
assertNotNull(ro);
} catch (SystemException e) {
fail(e.getLocalizedMessage());
} catch (BusinessException e) {
fail(e.getBusinessCode());
}
EasyMock.verify(mock);
}
/**
* MOCK PaymentReconService实现
* @return
*/
private PaymentReconService mock() {
PaymentReconRO mockRO = new PaymentReconRO(PaymentReconRO.Status.SUCESS, “OK”);
PaymentReconService mock = EasyMock.createMock(PaymentReconServiceImpl.class);
EasyMock.expect(mock.paymentSuccessRecon(EasyMock.anyObject(Long.class))).andReturn(mockRO);
EasyMock.replay(mock);
//这里把依赖的数据注进去
ReflectionTestUtils.s
领取专属 10元无门槛券
手把手带您无忧上云