单元测试编写规范、问题、解决

前置步骤

  1. 所有单测的上一级目录下 新建 BaseTestCase
    public class BaseTestCase {
    @Before
    public void init_mocks() {
        MockitoAnnotations.initMocks(this);
    }
    }
    
  2. 具体的单测类
    @RunWith(PowerMockRunner.class)
    @WebAppConfiguration
    @Log4j2
    public class BaseDataApiServiceImplTest extends BaseTestCase{
    	@InjectMocks
    	private static InnerDataApiServiceImpl client;
    	@Mock
    	private static InterfaceCallLogService interfaceCallLogService;
     	@Before
    	public void setUp() throws Exception {
        	client = new InnerDataApiServiceImpl();
        	ReflectionTestUtils.setField(client, "interfaceCallLogService", interfaceCallLogService);
    }
    	@SneakyThrows
    	@Test
    	public void getApiDataByInterfaceName() {
    		String interfaceName = CommonConstants.TEST_INTERFACENAME;
    		String inputParams = CommonConstants.TEST_INPUTPARAMS;
    		String accessToken = CommonConstants.TEST_ACCESSTOKEN;
    		client.getApiDataByInterfaceName(interfaceName, inputParams, accessToken);
    		}
    	}
    

主要参数释义

对应问题与解决

初晨暖阳,夜落星河。 少年披梦,远方有歌。 红黄之上,春夏晚风。 闲肆游走,人群熙攘。
原文地址:https://www.cnblogs.com/alidata/p/15160468.html