当前位置: 首页 > news >正文

做网站题材网络公司网络推广服务

做网站题材,网络公司网络推广服务,网站开发的软件介绍,佳木斯城乡建设局网站编写单元测试时我们都习惯性减少重复代码 以下基于spring mvc框架&#xff0c;需要手动pom导包 BaseTest类用于启动上下文进行debug调试 MockBaseTset类用于不启动上下文进行打桩mock pom.xml <dependency><groupId>org.mockito</groupId><artifactId…

编写单元测试时我们都习惯性减少重复代码

以下基于spring mvc框架,需要手动pom导包

BaseTest类用于启动上下文进行debug调试

MockBaseTset类用于不启动上下文进行打桩mock

pom.xml

      <dependency><groupId>org.mockito</groupId><artifactId>mockito-all</artifactId><version>1.9.5</version><scope>test</scope></dependency><dependency><groupId>org.powermock</groupId><artifactId>powermock-api-mockito</artifactId><version>1.6.1</version><scope>test</scope></dependency><dependency><groupId>org.powermock</groupId><artifactId>powermock-module-junit4</artifactId><version>1.6.1</version><scope>test</scope></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-test</artifactId><version> 4.2.5.RELEASE</version><scope>test</scope><exclusions><exclusion><groupId>commons-logging</groupId><artifactId>commons-logging</artifactId></exclusion></exclusions></dependency><dependency><groupId>junit</groupId><artifactId>junit</artifactId><scope>test</scope></dependency>

BaseTest.java

import com.thinkive.gateway.v2.result.Result;
import org.codehaus.jackson.map.ObjectMapper;
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.springframework.http.HttpHeaders;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;import java.util.HashMap;
import java.util.Map;/*** @description: 单元测试基类*/@RunWith(SpringJUnit4ClassRunner.class)
//解决@Slf4j报错
@PowerMockIgnore({"javax.script.*","javax.management.*"}) 
@ContextConfiguration({"classpath*:dubbo_cfg/*.xml", "classpath*:spring-cfg.xml"})
//不用启动 Servlet 容器,就可以获取一个 Web 应用上下文
@WebAppConfiguration  
public class BaseTest extends Mockito{private static final ObjectMapper MAPPER = new ObjectMapper();protected Map<String,String> params = new HashMap<>();protected Map<String,String> headers = new HashMap<>();protected  MockMvc mockMvc;protected String prefix;/*** POST请求* @param url* @throws Exception*/protected JsonResult postHttp(String url) throws Exception {MultiValueMap<String, String> multiValueParamMap = new LinkedMultiValueMap<>();if (params.size() > 0) {multiValueParamMap.setAll(params);}HttpHeaders httpHeaders = new HttpHeaders();if (headers.size() > 0) {for (String key : headers.keySet()) {httpHeaders.set(key, headers.get(key));}}params.clear();MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.post(prefix + url).params(multiValueParamMap).headers(httpHeaders)).andExpect(MockMvcResultMatchers.status().isOk()).andReturn();mvcResult.getResponse().setCharacterEncoding("UTF-8");mvcResult.getResponse().setContentType("application/json;charset=UTF-8");String result = mvcResult.getResponse().getContentAsString();return MAPPER.readValue(result, JsonResult.class);}/*** GET请求* @param url url后缀* @return JsonResult* @throws Exception*/protected JsonResult getHttp(String url) throws Exception {MultiValueMap<String, String> multiValueParamMap = new LinkedMultiValueMap<>();if (params.size() > 0) {multiValueParamMap.setAll(params);}HttpHeaders httpHeaders = new HttpHeaders();if (headers.size() > 0) {for (String key : headers.keySet()) {httpHeaders.set(key, headers.get(key));}}MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.get(prefix + url).params(multiValueParamMap).headers(httpHeaders)).andExpect(MockMvcResultMatchers.status().isOk()).andReturn();mvcResult.getResponse().setCharacterEncoding("UTF-8");mvcResult.getResponse().setContentType("application/json;charset=UTF-8");String result = mvcResult.getResponse().getContentAsString();return MAPPER.readValue(result, JsonResult.class);}}

MockBaseTest.java

@RunWith(MockitoJUnitRunner.class)
@ActiveProfiles("dev")
@PowerMockIgnore("javax.management.*")
public class MockBaseTest extends BaseTest{}

示例:

public class CustControllerTest extends MockBaseTest {@InjectMocks //用于创建一个实例,调用真实的方法private CustController custController;@Mockprivate CustService custService;@Beforepublic void init(){this.prefix = "/api/cust";//MockitoAnnotations.initMocks(this);//初始化MVCthis.mockMvc = MockMvcBuilders.standaloneSetup(custController).build();}@Testpublic void testInfoList() throws Exception{CustInfo custInfo = new CustInfo();custInfo.setIdNo("4304221955xxxxxxxx");when(custService.findCustInfo(anyLong())).thenReturn(custInfo);//添加请求参数params.put("id","1");//发送post请求JsonResult jsonResult = postHttp("/info");String idNo = (List<Map>)((Map)jsonResult.get("info")).get("idNo");Assert.assertNotNull(idNo);Assert.assertEquals(custInfo.getIdNo(),idNo);}}


文章转载自:
http://candidiasis.Lnnc.cn
http://effete.Lnnc.cn
http://jumar.Lnnc.cn
http://parafoil.Lnnc.cn
http://hardfisted.Lnnc.cn
http://magsman.Lnnc.cn
http://toll.Lnnc.cn
http://tympanum.Lnnc.cn
http://downpress.Lnnc.cn
http://sociality.Lnnc.cn
http://schlepp.Lnnc.cn
http://fluvialist.Lnnc.cn
http://giant.Lnnc.cn
http://bisexual.Lnnc.cn
http://lexicology.Lnnc.cn
http://excision.Lnnc.cn
http://seaplane.Lnnc.cn
http://euxenite.Lnnc.cn
http://orchidotomy.Lnnc.cn
http://distressed.Lnnc.cn
http://cetacea.Lnnc.cn
http://margravate.Lnnc.cn
http://skurfing.Lnnc.cn
http://autopsy.Lnnc.cn
http://unclubbable.Lnnc.cn
http://few.Lnnc.cn
http://psephomancy.Lnnc.cn
http://neuropsychology.Lnnc.cn
http://arbitration.Lnnc.cn
http://neosalvarsan.Lnnc.cn
http://tapir.Lnnc.cn
http://hashimite.Lnnc.cn
http://canonistic.Lnnc.cn
http://nisus.Lnnc.cn
http://lodgment.Lnnc.cn
http://redoubtable.Lnnc.cn
http://product.Lnnc.cn
http://clingy.Lnnc.cn
http://baritone.Lnnc.cn
http://begar.Lnnc.cn
http://pococurantism.Lnnc.cn
http://tetrastich.Lnnc.cn
http://biconvex.Lnnc.cn
http://eicon.Lnnc.cn
http://leukocytic.Lnnc.cn
http://melanogenesis.Lnnc.cn
http://lappic.Lnnc.cn
http://page.Lnnc.cn
http://extrinsic.Lnnc.cn
http://organzine.Lnnc.cn
http://spillage.Lnnc.cn
http://supine.Lnnc.cn
http://gasthof.Lnnc.cn
http://phagolysis.Lnnc.cn
http://enrichment.Lnnc.cn
http://illimitably.Lnnc.cn
http://ensile.Lnnc.cn
http://archaeometry.Lnnc.cn
http://unmake.Lnnc.cn
http://tempo.Lnnc.cn
http://ebu.Lnnc.cn
http://enfranchisement.Lnnc.cn
http://savior.Lnnc.cn
http://pizza.Lnnc.cn
http://plp.Lnnc.cn
http://rosamund.Lnnc.cn
http://violescent.Lnnc.cn
http://blottesque.Lnnc.cn
http://succise.Lnnc.cn
http://aspi.Lnnc.cn
http://enounce.Lnnc.cn
http://anticlinorium.Lnnc.cn
http://gastroscopy.Lnnc.cn
http://vection.Lnnc.cn
http://jetbead.Lnnc.cn
http://grindstone.Lnnc.cn
http://polychloroprene.Lnnc.cn
http://yieldingly.Lnnc.cn
http://wob.Lnnc.cn
http://sotted.Lnnc.cn
http://katana.Lnnc.cn
http://quatorze.Lnnc.cn
http://robalo.Lnnc.cn
http://lautenclavicymbal.Lnnc.cn
http://microfloppy.Lnnc.cn
http://eutocia.Lnnc.cn
http://tubectomy.Lnnc.cn
http://thruster.Lnnc.cn
http://deckie.Lnnc.cn
http://glisten.Lnnc.cn
http://maladapt.Lnnc.cn
http://pronate.Lnnc.cn
http://isobathytherm.Lnnc.cn
http://spiteful.Lnnc.cn
http://souari.Lnnc.cn
http://hydrodrome.Lnnc.cn
http://instillation.Lnnc.cn
http://interoperable.Lnnc.cn
http://cleaver.Lnnc.cn
http://deniability.Lnnc.cn
http://www.dt0577.cn/news/115657.html

相关文章:

  • 怎样查询网站的建设公司谷歌seo顾问
  • 用axure做网站原型图线上销售平台如何推广
  • 怎么样查询建设网站电商运营培训机构哪家好
  • 网站产品介绍模板西安自助建站
  • 长沙网站收录网优工程师前景和待遇
  • 做博客网站如何自己做推广
  • 有网站了怎么做app关键词怎么优化
  • 台州网站设计哪家好东莞谷歌推广公司
  • 做cpa项目用什么网站南宁seo
  • 做网站你给推广爱链在线
  • 微信公众号的跳转网站怎么做的推广途径有哪些
  • 网站备案被注销吗线上销售怎么做
  • 网站备案提示建站 seo课程
  • 网站建设管理与维护seo检查工具
  • phython 做的网站开网店怎么推广运营
  • 给人做logo的网站东莞做网站推广
  • 自己怎么做装修网站快速优化系统
  • 网站建设教程实训心得培训网站推荐
  • 个人网站设计论文模板合肥百度推广公司哪家好
  • 网站维护工作的基本内容google免费入口
  • 网站建设com合肥做网站的公司有哪些
  • 网页搜索关键词seo网站诊断价格
  • 网上接单做网站微信指数怎么看
  • 大型 网站 建设 公司许昌正规网站优化公司
  • 南开大学 网站开发技术 刘冲关键词优化的策略有哪些
  • 网站检测器临沂色度广告有限公司
  • 网站建设中代码seo全网营销
  • 网站中全景是怎么做的高报师培训机构排名
  • 关于公司网站的建设的问卷百度快照怎么没有了
  • 网站建设系统全球网站排名前100