标签:实现 unit ref com imp link path orm prepare
mock 构造函数
import static org.junit.Assert.*; import java.util.ArrayList; import org.junit.Test; import org.junit.runner.RunWith; import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PowerMockIgnore; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import com.tdtech.eplatform.gatekeeper.config.entity.Listenexternal; import com.tdtech.eplatform.gatekeeper.constant.IConfigFileSet; @RunWith(PowerMockRunner.class) @PrepareForTest(ExcelParasForListener.class) /* * About @PowerMockIgnore: * http://www.ryanchapin.com/fv-b-4-816/Java-PowerMock-Could-not-reconfigure-JMX-java-lang-LinkageError-Solution.html */ @PowerMockIgnore({ "javax.management.*" }) public class ExcelParasForListenerTest { private ExcelParasForListener excelParasForListener = new ExcelParasForListener(); @Test public void testLoadIPlistenerConfig() throws Exception { // mock ExcelReader constructor ExcelReader mocIPexcelReader = new ExcelReader(IConfigFileSet.easyconfTemplatePath, IConfigFileSet.sheetNameofListenIPMapping); PowerMockito.whenNew(ExcelReader.class) .withArguments(IConfigFileSet.importEasyconfFilePath, IConfigFileSet.sheetNameofListenIPMapping) .thenReturn(mocIPexcelReader); // test and verify ArrayList<Listenexternal> loadIPlistenerConfig = excelParasForListener.loadIPlistenerConfig(); assertEquals("10.10.10.11", loadIPlistenerConfig.get(0).getListenIP()); assertEquals(2404, loadIPlistenerConfig.get(0).getListenPort()); } }
可参考"如何使用PowerMock和Mockito来mock 1. 构造函数 2. 静态函数 3. 枚举实现的单例 4. 选择参数值做为函数的返回值":
http://www.blogjava.net/usherlight/archive/2015/06/16/425740.html
标签:实现 unit ref com imp link path orm prepare
原文地址:http://www.cnblogs.com/eaglediao/p/7492810.html