摘要:首先定义抽象类BaseTest
首先定义抽象类BaseTest
package com.geostar.gfstack.operationcenter.common.util; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import org.junit.runner.RunWith; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = "classpath:config/spring/applicationContext.xml") public abstract class BaseTest { private static final Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().setPrettyPrinting().create(); public static void printJson(Object obj){ print("*************************** printJson start ***************************"); print(gson.toJson(obj)); print("**************************** printJson end ****************************"); } public static void print(Object obj){ System.out.println(obj); } }
实现类直接使用@Resource注入bean,使用@Test注解编写测试方法
package com.geostar.gfstack.operationcenter.core.cloud.service.test; import com.geostar.gfstack.operationcenter.common.exception.GeoStackException; import com.geostar.gfstack.operationcenter.common.util.BaseTest; import com.geostar.gfstack.operationcenter.core.cloud.log.OrdersProcessLog; import com.geostar.gfstack.operationcenter.core.cloud.model.Orders; import com.geostar.gfstack.operationcenter.core.cloud.service.IOrderService; import org.junit.Test; import javax.annotation.Resource; import java.util.List; public class OrderServiceTest extends BaseTest { @Resource private IOrderService orderService; @Test public void saveOrders() throws GeoStackException { Orders orders = new Orders(); orders.setOrderId(String.valueOf(System.currentTimeMillis())); orders.setOrderRemark("测试订单"); orders.setCheckState("99999"); orderService.saveOrders(orders); } }
本文由职坐标整理并发布,希望对同学们有所帮助。了解更多详情请关注职坐标软件测试之测试工具频道!
您输入的评论内容中包含违禁敏感词
我知道了
请输入正确的手机号码
请输入正确的验证码
您今天的短信下发次数太多了,明天再试试吧!
我们会在第一时间安排职业规划师联系您!
您也可以联系我们的职业规划师咨询:
版权所有 职坐标-一站式IT培训就业服务领导者 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
沪公网安备 31011502005948号